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, PDF forms

Views

152

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
community guidelines
Adobe Community Professional ,
Jan 10, 2020 Jan 10, 2020

Copy link to clipboard

Copied

Where does you use this script?

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
community guidelines
New Here ,
Jan 12, 2020 Jan 12, 2020

Copy link to clipboard

Copied

Adobe Accrobat DC standard

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
community guidelines
Adobe Community Professional ,
Jan 15, 2020 Jan 15, 2020

Copy link to clipboard

Copied

Does you use the code as calculation script?

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
community guidelines
Most Valuable Participant ,
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. 

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

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
community guidelines
Most Valuable Participant ,
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.

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

 

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
community guidelines
Most Valuable Participant ,
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.

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
community guidelines
Adobe Community Professional ,
Jan 13, 2020 Jan 13, 2020

Copy link to clipboard

Copied

Does you divide by zero?

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
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.

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
community guidelines
Most Valuable Participant ,
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?

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
community guidelines
Adobe Community Professional ,
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

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
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.

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
community guidelines
Adobe Community Professional ,
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

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

Copy link to clipboard

Copied

Do you have any calculations that are using division?

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
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 = "";}

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
community guidelines
Adobe Community Professional ,
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

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

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