Amount In Words

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';
OnesTextDevil:= 'Six';
OnesText[7] := 'Seven';
OnesTextMusic:= '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';
TensTextDevil:= 'Sixty';
TensText[7] := 'Seventy';
TensTextMusic:= 'Eighty';
TensText[9] := 'Ninety';

ThousText[1] := 'Hundred';
ThousText[2] := 'Thousand';
ThousText[3] := 'Million';
ThousText[4] := 'Billion';
ThousText[5] := 'Trillion';

  • hi,
    Why to write all this code. All this code exist in standard NAV Report 1401 Pre 2015 (i think) and in latest version you can call the function from Report 10400.
    You need to pass required parameter and system will do for you.
  • In reply to Saurav Dhyani:

    Sure you are right Saurav, The code is actually for NAV 09, had to support a client in NAV 09 with amount in words functionality, here the client requires the whole part and the decimal part of the value passed, to be converted fully to words with the main currency name and the denomination name suffixed accordingly.
    The FormatNoText function in nav report 1401, does not convert the decimal places of the given value to words, only the integer(whole) value is converted to words.

    Regards.
  • In reply to Saurav Dhyani:

    Hi Saurav,
    That is correct. Only "problem" report 10400 is not a W1 object. It's in the US version as Check Translation Management. But for example then it's not in the Danish version.
  • In reply to Erik P. Ernst:

    Yes but 1401 is a W1 report and it will have refrence to similar report like 10400 for the locaized or W1 version. I would have checked it if i would have W1 DVD.
Related