Skip to main content
creativemarks
Known Participant
November 25, 2016
Question

Amount or figures convert in to words

  • November 25, 2016
  • 2 replies
  • 2134 views

How can a set a field to amounts and other convert it into words.

regards

This topic has been closed for replies.

2 replies

creativemarks
Known Participant
November 28, 2016

Yes Sir,

Thankyou i just figured it out few mins back, i am learning by your help thank you.

regards

Inspiring
November 25, 2016

This question has been asked and answered several times. You should be able to find the answer using search.

You must add a user written function.

creativemarks
Known Participant
November 25, 2016

Dear Sir,

I have found the answer but i can not figure out where to place which script.

i found this:

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 this:

event.value = "";

var f = this.getField("Initial Amount Deposit");

if(f.valueAsString != "") {

event.value = ConvertToWords(f.value);

}

I am typing amount in Initial Amount Deposit field and want words in Initial Amount Txt.

Please help.

Inspiring
November 25, 2016

It can go in any of a couple of places. The most common is as a document level function. It can be included in the same action as the action as the second block of code.