• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

help with java script figure to amount script

New Here ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

i found this script online it should change amount from number to words but it don't work except for USD

input text field is FIELD_APR

output text field is FIELD_APR_TEXT

 

pulldown menu have these 3 values USD/EUR/EGP

if (CUR=USD)

{
  
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) {
cNum = String(num);
nNum = Number(cNum.charAt(0));
cWords += aOnes[nNum] + " Hundred";
num %= 100;
if (num > 0)
cWords += " and "
}

if (num > 19) {
cNum = String(num);
nNum = Number(cNum.charAt(0));
cWords += aTens[nNum - 2];
num %= 10;
if (num > 0)
cWords += "-";
}
 
if (num > 0) {
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;
}
var f = this.getField("FIELD_APR");
event.value = ConvertToWords(f.value);
this.getField("FIELD_APR_TEXT").value = ConvertToWords(f.value);
  
  }

else if(CUR=EUR)

{
  
  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) {
cNum = String(num);
nNum = Number(cNum.charAt(0));
cWords += aOnes[nNum] + " Hundred";
num %= 100;
if (num > 0)
cWords += " and "
}

if (num > 19) {
cNum = String(num);
nNum = Number(cNum.charAt(0));
cWords += aTens[nNum - 2];
num %= 10;
if (num > 0)
cWords += "-";
}
 
if (num > 0) {
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) ? "Euro and " : "Euros 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;
}
var f = this.getField("FIELD_APR");
event.value = ConvertToWords(f.value);
this.getField("FIELD_APR_TEXT").value = ConvertToWords(f.value);
  
  }

else

{

    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) {
cNum = String(num);
nNum = Number(cNum.charAt(0));
cWords += aOnes[nNum] + " Hundred";
num %= 100;
if (num > 0)
cWords += " and "
}

if (num > 19) {
cNum = String(num);
nNum = Number(cNum.charAt(0));
cWords += aTens[nNum - 2];
num %= 10;
if (num > 0)
cWords += "-";
}
 
if (num > 0) {
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) ? "Egyptian pound and " : "Egyptian pounds 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) + " Piastres";
else
cWords += "Zero Piastres";
 
return cWords;
}
var f = this.getField("FIELD_APR");
event.value = ConvertToWords(f.value);
this.getField("FIELD_APR_TEXT").value = ConvertToWords(f.value);
}

 

TOPICS
How to , JavaScript , PDF forms

Views

850

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
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 13, 2021 Apr 13, 2021

Votes

Translate

Translate
Community Expert ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

The comparison operator of JS is "==" (or "==="), not "=". That's used to assign a value.

Votes

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
community guidelines
New Here ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

it works either way but when you choose another dropdown menu value it doesn't work ( EUR and EGP currencies)

Votes

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
community guidelines
Community Expert ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

It doesn't work either way. The way you have your code set up the currency will always be USD.

Votes

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
community guidelines
New Here ,
Mar 31, 2021 Mar 31, 2021

Copy link to clipboard

Copied

can you please explain that or how to change it.

Votes

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
community guidelines
Community Expert ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

I believe I did already...

Votes

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
community guidelines
Community Expert ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

Also, strings need to be in quotes.

So, for example, change this:

if (CUR=USD)

To this:

if (CUR=="USD")

 

Votes

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
community guidelines
New Here ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

Anyone can offer help

Votes

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
community guidelines
New Here ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

same problem i also changed the names to make sure

Votes

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
community guidelines
Community Expert ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

Check the JS Console. The error message is pretty clear...

Votes

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
community guidelines
Community Expert ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

LATEST

Votes

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
community guidelines