Recently I had a chance to work on a client’s requirement where it was required to print the amount in words along with currency name (e.g. $500.42 = Five Hundred Dollars and Forty Two Cents).
In Dynamics AX there is a built-in function numeralsToText in Global class which does the conversion of numbers into text. But this function does not give you the facility to print the currency name in the converted text.
To accomplish above scenario, I had to write my own code with the use of numeralsToText method to get currency name along with the amount. The following method with three parameters (real amount, str currency1, str currency2) does the actual work.
static str convertAmountInWords(real _amount, str _currency1, str _currency2)
str word, decWord;
int repPos, repPos1;
word = Global::numeralsToTxt_EN(_amount);
repPos = strscan(word, ‘ and’, 1, strlen(word));
intNum = _amount;
decimals = _amount – intNum;
if (decimals == 0.00)
word = strdel(strpoke(word, strfmt(‘ %1 and No %2’, _currency1, _currency2), repPos), 1, 4);
decWord = substr(num2str(decimals, 0, 2, 1, 1), 3, 2);
decWord = Global::numeralsToTxt_EN(str2num(decWord));
repPos1 = strscan(decWord, ‘ and’, 1, strlen(decWord));
decWord = strpoke(decWord, strfmt(‘ %1’, _currency2), repPos1);
decWord = strdel(decWord, 1, 4);
word = strdel(strpoke(word, strFmt(‘ %1 and %2’, _currency1, decWord), repPos), 1, 4);
word = strdel(word, strscan(word, ‘/100’, 1, strlen(word)), 4);
Users can add this method in their class and call it with required amount and currency names. For example:
<YourClassName>::convertAmountInWords(64300.53, ‘Dollar’, ‘Cents’);
Sixty Four Thousand Three Hundred Dollar and Fifty Three Cents