Convert a field from Figure To Words in Indian currency formmat

New Here ,
Aug 09, 2017

Copy link to clipboard

Copied

Can anyone provide me with the proper script for converting the amount in figure to amount in words as per the indian currency format such as

FOR Rs. 25,25,25,225.25 we spell it as Twenty Five Crore Twenty Five Lakh Twenty Five Thousand Two Hundred Twenty Five Rupees and Twenty Five Paise only.

I got some script from forum which is :

aTens = [ "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"];

aOnes = [ "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",

  "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen",

  "Nineteen" ];

function ConvertToHundreds(num)

{

   var cNum, nNum;

   var cWords = "";

   num %= 1000;

   if (num > 99) {

      /* Hundreds. */

      cNum = String(num);

      nNum = Number(cNum.charAt(0));

      cWords += aOnes[nNum] + " Hundred";

      num %= 100;

      if (num > 0)

         cWords += " and "

   }

   if (num > 19) {

      /* Tens. */

      cNum = String(num);

      nNum = Number(cNum.charAt(0));

      cWords += aTens[nNum - 2];

      num %= 10;

      if (num > 0)

         cWords += "-";

   }

   if (num > 0) {

      /* Ones and teens. */

      nNum = Math.floor(num);

      cWords += aOnes[nNum];

   }

   return cWords;

}

function ConvertToWords(num)

{

   var aUnits = [ "Thousand", "Million", "Billion", "Trillion", "Quadrillion" ];

   var cWords = (num >= 1 && num < 2) ? "Dollar and " : "Dollars and ";

   var nLeft = Math.floor(num);

   for (var i = 0; nLeft > 0; i++) {

       if (nLeft % 1000 > 0) {

          if (i != 0)

             cWords = ConvertToHundreds(nLeft) + " " + aUnits[i - 1] + " " + cWords;

          else

             cWords = ConvertToHundreds(nLeft) + " " + cWords;

       }

       nLeft = Math.floor(nLeft / 1000);

   }

   num = Math.round(num * 100) % 100;

   if (num > 0)

      cWords += ConvertToHundreds(num) + " Cents";

   else

      cWords += "Zero Cents";

   return cWords;

}

and when i replaced all the dollars and cents with Rupees and paise respectively and million with Lakh but still the value does not comes good and it spells like for rs. 22,22,12,196.23, it spells Two Hundred Twenty Two Lakh Two Hundered Twelve Thouand One Hundred Ninety Six Rupees and Twenty Three Paise Only  , Rather It should spell like Twenty Two Crore Twenty Two Lakh Twelve Thousand One Hundered Ninety Six Rupees And Twenty Three Paise Only

TOPICS
Acrobat SDK and JavaScript, Windows

Views

1.2K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Convert a field from Figure To Words in Indian currency formmat

New Here ,
Aug 09, 2017

Copy link to clipboard

Copied

Can anyone provide me with the proper script for converting the amount in figure to amount in words as per the indian currency format such as

FOR Rs. 25,25,25,225.25 we spell it as Twenty Five Crore Twenty Five Lakh Twenty Five Thousand Two Hundred Twenty Five Rupees and Twenty Five Paise only.

I got some script from forum which is :

aTens = [ "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"];

aOnes = [ "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",

  "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen",

  "Nineteen" ];

function ConvertToHundreds(num)

{

   var cNum, nNum;

   var cWords = "";

   num %= 1000;

   if (num > 99) {

      /* Hundreds. */

      cNum = String(num);

      nNum = Number(cNum.charAt(0));

      cWords += aOnes[nNum] + " Hundred";

      num %= 100;

      if (num > 0)

         cWords += " and "

   }

   if (num > 19) {

      /* Tens. */

      cNum = String(num);

      nNum = Number(cNum.charAt(0));

      cWords += aTens[nNum - 2];

      num %= 10;

      if (num > 0)

         cWords += "-";

   }

   if (num > 0) {

      /* Ones and teens. */

      nNum = Math.floor(num);

      cWords += aOnes[nNum];

   }

   return cWords;

}

function ConvertToWords(num)

{

   var aUnits = [ "Thousand", "Million", "Billion", "Trillion", "Quadrillion" ];

   var cWords = (num >= 1 && num < 2) ? "Dollar and " : "Dollars and ";

   var nLeft = Math.floor(num);

   for (var i = 0; nLeft > 0; i++) {

       if (nLeft % 1000 > 0) {

          if (i != 0)

             cWords = ConvertToHundreds(nLeft) + " " + aUnits[i - 1] + " " + cWords;

          else

             cWords = ConvertToHundreds(nLeft) + " " + cWords;

       }

       nLeft = Math.floor(nLeft / 1000);

   }

   num = Math.round(num * 100) % 100;

   if (num > 0)

      cWords += ConvertToHundreds(num) + " Cents";

   else

      cWords += "Zero Cents";

   return cWords;

}

and when i replaced all the dollars and cents with Rupees and paise respectively and million with Lakh but still the value does not comes good and it spells like for rs. 22,22,12,196.23, it spells Two Hundred Twenty Two Lakh Two Hundered Twelve Thouand One Hundred Ninety Six Rupees and Twenty Three Paise Only  , Rather It should spell like Twenty Two Crore Twenty Two Lakh Twelve Thousand One Hundered Ninety Six Rupees And Twenty Three Paise Only

TOPICS
Acrobat SDK and JavaScript, Windows

Views

1.2K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 09, 2017 0

Have something to add?

Join the conversation