Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
0

Pdf script Convert numerical to words (eg. 60 to Sixty, 450 to four hunder fifty)

Engaged ,
Oct 03, 2016 Oct 03, 2016

Sir / Madam

I got the following script from web which converts numerical currency into words......... but i don't want these currency (eg.dollar and cents).. i want it to be modified so that i can have plain conversion from numerical to words.. .like  1056 to one thousand fifty six..

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;

}

TOPICS
Acrobat SDK and JavaScript , Windows
649
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 03, 2016 Oct 03, 2016

I edited the above script to following  ... but it return me like this ... eg. 600 to SIX HUNDRED FALSE....... where does false come from? plz help.

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);

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;

cWords += ConvertToHundreds(num);

return cWords;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 04, 2016 Oct 04, 2016

The false comes from:

var cWords = (num >= 1 && num < 2);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 04, 2016 Oct 04, 2016

Then wat should it be.. should i delete that text..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 04, 2016 Oct 04, 2016

Look at the difference with your first posting:

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 04, 2016 Oct 04, 2016

But i don't want the dollar written.. i want plain text.....thatswhy i removed the dollar line.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 04, 2016 Oct 04, 2016
LATEST

Then use:

var cWords = "";

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