Sunday, June 24, 2012

Decimal Number to Words in Crystal Report

Simply replace the values with your field:

Towords(truncate(8900.89), 0) + " and " + towords(abs(100 * (truncate(8900.89)- 8900.89)), 0) + " centavos";

result is: eight thousand nine hundred and eighty-nine centavos

Why:
Towords(truncate(8900.89), 0) returns 8900, the "," 0 tells the function to ignore the decimal place.

(abs(100 * (8900.89 - truncate(8900.89)) abs converts it to a positive value always just in case and multiplies the value to be non decimal.

If you have more decimal places you'll have to adjust the 100 multiplier


Extra : With First letter upper case:

UpperCase(Left(Towords(truncate({vwchequereportprint.phAmount}), 0),1)) +
 Right (towords(truncate({vwchequereportprint.phAmount}), 0),
Length (towords(truncate({vwchequereportprint.phAmount}), 0))-1)
+" dollar"+(towords(abs(100 * (truncate({vwchequereportprint.phAmount})-{vwchequereportprint.phAmount})), 0)+ " laari")