Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using toword function

Status
Not open for further replies.

snowbunny2

Technical User
Aug 12, 2004
2
GB
Hi all

Can you please help?

I have a report which calculates sum@details only - this is a currency field and it works fine.

However, what I also need to be able to do is to transfer these figures into words to be used elsewhere in the report. I am aware of the "toword" feature, but as I'm working in currency, if there are figures after the decimal place, it shows e.g. 59/100 for 59p is there any way I can change this, also if the currency is just returning round pounds I would like to do away with the 00/100 feature and replace it with the word only.

Any help would be appreciated
 
First, split amount into pounds and pence. You can do this using a @Pounds that says Truncate(@amount, 0). Subtract this from the original amount to get pence.

Edit the pence, something like @SayPence
Code:
if @pence = 0 then " only"
else " & " & Totext(@pence) & " pence"

Finally merge the two
Code:
ToWords(@Pounds) & @SayPence
It helps to give your Crystal version, since newer versions have extra solutions, and some extra problems. I use Crystal 8.5

Madawc Williams (East Anglia)
 
Try the following formula {@towords}:

If mid(totext({table.currency}),instr(totext({table.currency}),".")+1) = "00" then
left(towords({table.currency}),instrrev(towords({table.currency}),"and")-1) +"pounds" else
left(towords({table.currency}),instrrev(towords({table.currency}),"and")-1) +"pounds and " +
mid(totext({table.currency}),instr(totext({table.currency}),".")+1) + " pence"

Then if you want this displayed in proper case, create a second formula:

whileprintingrecords;
stringvar array x;
redim preserve x[ubound(x)+1];
numbervar counter := 0;
stringvar result := "";

x := split({@towords}," ");
for counter := 1 to ubound(x) do(
result := result + ucase(left(x[counter],1))+mid(x[counter],2) + " ");
replace(result,"And","and");

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top