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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to show a number as a word on a report 1

Status
Not open for further replies.

shehul

Programmer
Jun 2, 2003
19
GB
I need to show a numeric amount in words on the report. How do I do it.
For eg 345.5 as Three Four Five Cents Five
 
----start code------
Dim i as number
Dim Output as String
Dim WholeWord as String
for i = 1 to 8
if mid(ToText({YourTable.YourField}),i,1) = "1" then Output = "one" else
if mid(ToText({YourTable.YourField}),i,1) = "2" then Output = "two" else
if mid(ToText({YourTable.YourField}),i,1) = "3" then Output = "three" else
if mid(ToText({YourTable.YourField}),i,1) = "4" then Output = "four" else
if mid(ToText({YourTable.YourField}),i,1) = "5" then Output = "five" else
if mid(ToText({YourTable.YourField}),i,1) = "6" then Output = "six" else
if mid(ToText({YourTable.YourField}),i,1) = "7" then Output = "seven" else
if mid(ToText({YourTable.YourField}),i,1) = "8" then Output = "eight" else
if mid(ToText({YourTable.YourField}),i,1) = "9" then Output = "nine" else
if mid(ToText({YourTable.YourField}),i,1) = "0" then Output = "zero"
if mid(ToText({YourTable.YourField}),i,1) = "." then Output = "cents"
if mid(ToText({YourTable.YourField}),i,1) = "," then Output = "comma"

WholeWord = WholeWord + " " + Output
Next i

formula = WholeWord
-----end code------
Be sure to set the interpretation for this formula to Basic... Good Luck

Thadeus
 
In CR 8.0 (I'm not sure about earlier versions) there is a "towords" function:

towords({table.value})

For a value = 345.5, it would give:

three hundred forty-five and 50/100

It is possible to adapt this more specifically, but it is unclear what you want your final results to be.

-LB
 
Thanks a lot for the help.
I couldnt use towords as I coulndt find any way of showing 50/100 as cents five
If there is some way to do that then I would prefer using towords
 
I agree with you that the 45/100 is horrible-looking. Fortunately there are ways round it. In Crystal 8.5 you could do the following

a) Create a formual Whole_Value,
Truncate({your.value})
This gives you the value minus the fractional portion.

b) Create a formula Fract_Value
100*(Whole_Value - {your.value})
this gives the fractional part as a number

c) Create a formula Say_Value
Towords(Whole_Value) & " cents "
& Towords(Fract_Value)

You could also get fancy and test Fract_Value for being zero, saying "exactly" if this were the case.

Madawc Williams
East Anglia, Great Britain
 
Correction, the formual in (b) should be
100*({your.value} - Whole_Value)


Madawc Williams
East Anglia, Great Britain
 
There is a way :

Local StringVar AmountVar := totext(345.5,2,"");
ToWords(Truncate(345.5),0)&
" Dollars "&
ToWords(tonumber(Right(AmountVar,Len(AmountVar)-instr(AmountVar,"."))),0)&
" cents";

This gives,
three hundred forty-five Dollars fifty cents

Hope this helps.....

Reebo
Scotland (Sunny with a Smile)
 
Try this:

ToWords(truncate({table.value},0),0)+" cents "+ToWords(Val(Right(totext({table.value}),2))/10,0)

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top