Original code from Jonathan Archer https://community.dynamics.com/nav/b/moxie4nav/archive/2014/12/08/numbers-to-words
For usage run (sample):
InitTextVariables;
AmountInWords := NumberInWords(123456.78,'Cedis','Pesewas');
Message(AmountInWords);
**NumberInWords(number : Decimal;CurrencyName : Text[30];DenomName : Text[30]) : Text[300]**
WholePart := ROUND(ABS(number),1,'<');
DecimalPart := ABS((ABS(number) - WholePart)*100);
WholeInWords := NumberToWords(WholePart,CurrencyName);
IF DecimalPart <> 0 THEN BEGIN
DecimalInWords := NumberToWords(DecimalPart,DenomName);
WholeInWords := WholeInWords + ' and ' + DecimalInWords;
END;
AmountInWords := '****' + WholeInWords + ' Only';
EXIT (AmountInWords);
**// local variables NumberInWords**
Parameters
Var Name DataType Subtype Length
No number Decimal
No CurrencyName Text 30
No DenomName Text 30
Return Value
Return Type Length
Text 300
**NumberToWords(number : Decimal;appendScale : Text[30]) : Text[300]**
numString := '';
IF number < 100 THEN
IF number < 20 THEN BEGIN
IF number <> 0 THEN numString := OnesText[number];
END ELSE BEGIN
numString := TensText[number DIV 10];
IF (number MOD 10) > 0 THEN
numString := numString + ' ' + OnesText[number MOD 10];
END
ELSE BEGIN
pow := 0;
powStr := '';
IF number < 1000 THEN BEGIN // number is between 100 and 1000
pow := 100;
powStr := ThousText[1];
END ELSE BEGIN // find the scale of the number
log := ROUND(STRLEN(FORMAT(number DIV 1000))/3,1,'>');
pow := POWER(1000, log);
powStr := ThousText[log + 1];
END;
numString := NumberToWords(number DIV pow, powStr) + ' ' + NumberToWords(number MOD pow,'');
END;
EXIT(DELCHR(numString,'<>',' ') + ' ' + appendScale);
__**// local variables NumberToWords**__
Parameters
Var Name DataType Subtype Length
No number Decimal
No appendScale Text 30
Return Value
Return Type Length
Text 300
Variables
Name DataType Subtype Length
numString Text 300
pow Integer
powStr Text 50
log Integer
//Global Variables
// OnesText Text 90 | Dim:20
// TensText Text 90 | Dim:10
// ThousText Text 90 | Dim:5
**Set Dimension on the Property Page For The Global Variable**
Name DataType Subtype Length
OnesText Text 90
TensText Text 90
ThousText Text 30
AmountInWords Text 300
WholeInWords Text 300
DecimalInWords Text 300
WholePart Integer
DecimalPart Integer
InitTextVariable()
OnesText[1] := ‘One’;
OnesText[2] := ‘Two’;
OnesText[3] := ‘Three’;
OnesText[4] := ‘Four’;
OnesText[5] := ‘Five’;
OnesText[6]:= ‘Six’;
OnesText[7] := ‘Seven’;
OnesText[8]:= ‘Eight’;
OnesText[9] := ‘Nine’;
OnesText[10] := ‘Ten’;
OnesText[11] := ‘Eleven’;
OnesText[12] := ‘Twelve’;
OnesText[13] := ‘Thirteen’;
OnesText[14] := ‘Fourteen’;
OnesText[15] := ‘Fifteen’;
OnesText[16] := ‘Sixteen’;
OnesText[17] := ‘Seventeen’;
OnesText[18] := ‘Eighteen’;
OnesText[19] := ‘Nineteen’;
TensText[1] := ‘’;
TensText[2] := ‘Twenty’;
TensText[3] := ‘Thirty’;
TensText[4] := ‘Forty’;
TensText[5] := ‘Fifty’;
TensText[6]:= ‘Sixty’;
TensText[7] := ‘Seventy’;
TensText[8]:= ‘Eighty’;
TensText[9] := ‘Ninety’;
ThousText[1] := ‘Hundred’;
ThousText[2] := ‘Thousand’;
ThousText[3] := ‘Million’;
ThousText[4] := ‘Billion’;
ThousText[5] := ‘Trillion’;