1 Reply Latest reply on May 11, 2015 2:03 PM by gkaiseril

# How  to convert amount with decimal points to words based on various currencies selected?

How  to convert amount with decimal points to words based on various currencies selected ?

I am able to convert amount without decimal points  to words based on various currencies selected Please provide a solution at the earliest.

My code is as follows:

function number2text(value) {

var fraction = Math.round(frac(value)*100);

var f_text  = "";

if(fraction > 0) {

f_text = "AND "+Number(fraction);

}

return Number(value)+" "+f_text;

}

function frac(f) {

return f % 1;

}

function Number(number)

{

if ((number < 0) || (number > 999999999))

{

return "NUMBER OUT OF RANGE!";

}

var Gn = Math.floor(number / 10000000);  /* Crore */

number -= Gn * 10000000;

var kn = Math.floor(number / 100000);     /* lakhs */

number -= kn * 100000;

var Hn = Math.floor(number / 1000);      /* thousand */

number -= Hn * 1000;

var Dn = Math.floor(number / 100);       /* Tens (deca) */

number = number % 100;               /* Ones */

var tn= Math.floor(number / 10);

var one=Math.floor(number % 10);

var res = "";

if (Gn>0)

{

res += (Number(Gn) + " CRORE");

}

if (kn>0)

{

res += (((res=="") ? "" : " ") +

Number(kn) + " LAKH");

}

if (Hn>0)

{

res += (((res=="") ? "" : " ") +

Number(Hn) + " THOUSAND");

}

if (Dn)

{

res += (((res=="") ? "" : " ") +

Number(Dn) + " HUNDRED");

}

var ones = Array("", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX","SEVEN", "EIGHT", "NINE", "TEN", "ELEVEN", "TWELVE", "THIRTEEN","FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN","NINETEEN");

var tens = Array("", "", "TWENTY", "THIRTY", "FOURTY", "FIFTY", "SIXTY","SEVENTY", "EIGHTY", "NINETY");

if (tn>0 || one>0)

{

if (!(res==""))

{

res += " AND ";

}

if (tn < 2)

{

res += ones[tn * 10 + one];

}

else

{

res += tens[tn];

if (one>0)

{

res += (" " + ones[one]);

}

}

}

if (res=="")

{

res = "ZERO";

}

return res;

}

function number2text(value) {

var fraction = Math.round(frac(value)*100);

var f_text  = "";

if(fraction > 0) {

f_text = "AND "+Number(fraction);

}

return Number(value)+" "+f_text;

}

function frac(f) {

return f % 1;

}

function Number(number)

{

if ((number < 0) || (number > 999999999))

{

return "NUMBER OUT OF RANGE!";

}

var Gn = Math.floor(number / 10000000);  /* Crore */

number -= Gn * 10000000;

var kn = Math.floor(number / 100000);     /* lakhs */

number -= kn * 100000;

var Hn = Math.floor(number / 1000);      /* thousand */

number -= Hn * 1000;

var Dn = Math.floor(number / 100);       /* Tens (deca) */

number = number % 100;               /* Ones */

var tn= Math.floor(number / 10);

var one=Math.floor(number % 10);

var res = "";

if (Gn>0)

{

res += (Number(Gn) + " CRORE");

}

if (kn>0)

{

res += (((res=="") ? "" : " ") +

Number(kn) + " LAKH");

}

if (Hn>0)

{

res += (((res=="") ? "" : " ") +

Number(Hn) + " THOUSAND");

}

if (Dn)

{

res += (((res=="") ? "" : " ") +

Number(Dn) + " HUNDRED");

}

var ones = Array("", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX","SEVEN", "EIGHT", "NINE", "TEN", "ELEVEN", "TWELVE", "THIRTEEN","FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN","NINETEEN");

var tens = Array("", "", "TWENTY", "THIRTY", "FOURTY", "FIFTY", "SIXTY","SEVENTY", "EIGHTY", "NINETY");

if (tn>0 || one>0)

{

if (!(res==""))

{

res += " AND ";

}

if (tn < 2)

{

res += ones[tn * 10 + one];

}

else

{

res += tens[tn];

if (one>0)

{

res += (" " + ones[one]);

}

}

}

return res;

}

if (this.getField("rdoGpAmountType").value == "Debit")

{

if(event.value!="")

{

if(event.value=="0")

{

this.getField("txtAmountInWords").value = "ZERO ONLY";

}

else

{

this.getField("txtAmountInWords").value = number2text(this.getField

("txtDebitAmount").value)+" "+"ONLY";

}

}

else

{

this.getField("txtAmountInWords").value="";

}

}

• ###### 1. Re: How  to convert amount with decimal points to words based on various currencies selected?

Selected where?

JavaScript in a PDF cannot access the currency values on the formatting tab, but it can set the currency.

You will need to edit the function for the various languages.