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

Percent and decimal script

New Here ,
Jan 10, 2020 Jan 10, 2020

Copy link to clipboard

Copied

How do I use the below script on more than 1 field as current it gives an error on other fields

if (event.value != "") {
event.value = util.printf("%0.2f",event.value)+"%";
}

 

Percent.PNG

TOPICS
Acrobat SDK and JavaScript

Views

1.2K

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 ,
Jan 10, 2020 Jan 10, 2020

Copy link to clipboard

Copied

Where does you use this script?

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 ,
Jan 12, 2020 Jan 12, 2020

Copy link to clipboard

Copied

Adobe Accrobat DC standard

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 ,
Jan 15, 2020 Jan 15, 2020

Copy link to clipboard

Copied

Does you use the code as calculation script?

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
LEGEND ,
Jan 10, 2020 Jan 10, 2020

Copy link to clipboard

Copied

By design, util.printf("%0.2f",x) will write 1.#R where x is not a number. 

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 ,
Jan 13, 2020 Jan 13, 2020

Copy link to clipboard

Copied

Please simplify your response.

How do I my code to avoid this from happening

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
LEGEND ,
Jan 13, 2020 Jan 13, 2020

Copy link to clipboard

Copied

Do not format data that is not a number. Check your input. 

Don't ask me to write your script, please.

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 ,
Jan 13, 2020 Jan 13, 2020

Copy link to clipboard

Copied

I changed the format to number, now I get the warning "The value entered does not match the format of the Field {Field name}Warning.PNG

 

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
LEGEND ,
Jan 13, 2020 Jan 13, 2020

Copy link to clipboard

Copied

As I have said, your information is at this point NOT A NUMBER. The error is just correct. For example this can happen if you have not yet typed anything in one of your fields, but you are calculating with it. This is a very common issue with forms, and means that most calculation scripts must carefully check their inputs.

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 ,
Jan 13, 2020 Jan 13, 2020

Copy link to clipboard

Copied

Does you divide by zero?

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 ,
Jan 13, 2020 Jan 13, 2020

Copy link to clipboard

Copied

No, it is a code line to output a decimal and percentage sign.

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
LEGEND ,
Jan 13, 2020 Jan 13, 2020

Copy link to clipboard

Copied

You must check your input, I have said. What are your inputs and where are they from?

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 ,
Jan 14, 2020 Jan 14, 2020

Copy link to clipboard

Copied

Try this, remove the format script so you can see what the "value" is that is causeing trouble. Then you can add code to test for that value. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Jan 16, 2020 Jan 16, 2020

Copy link to clipboard

Copied

I removed the string "%" and there is no error but once the string is removed there is no need for the script as the number format category displays the decimal. The script was created to have both the decimal and % sign out put. Another way would be using the percentage category and write a script to divide the value by 100.

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 ,
Jan 18, 2020 Jan 18, 2020

Copy link to clipboard

Copied

So the idea is to find out what value is causing the problem with util.printf. Did you find out this infomation?

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
LEGEND ,
Jan 18, 2020 Jan 18, 2020

Copy link to clipboard

Copied

Do you have any calculations that are using division?

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 ,
Jan 23, 2020 Jan 23, 2020

Copy link to clipboard

Copied

I updated my program to show decimal and % sign on my calculation

var x = Number(event.value).toFixed(2);
event.value = x.toString()+ " %"
if(event.value == 0 || event.value == "0.00 %") {
event.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
Community Expert ,
Jan 23, 2020 Jan 23, 2020

Copy link to clipboard

Copied

Is it working now?

You know, that after line #2 that "event.value" will never be 0. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Jan 24, 2020 Jan 24, 2020

Copy link to clipboard

Copied

LATEST

Yes it is working. Sometimes the form is printed without filling the fields so we have to remove the 0

Percent.PNG

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