Adding a script to limit to 2 decimal points

New Here ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

I have a Java script to make a calculation a percentage: 

 

if (event.value) event.value+="%"

 

it works great but how to I fix it so it only will calculate to 2 decimal points? And where do I add it ?

I am a total rookie at this. 

Views

115

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 ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

When you post a question you always need to tell the program you are using
There are MANY programs in a full subscription, plus other non-subscription programs
Please post the exact name of the Adobe program you use so a Moderator may move this message to that forum

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 ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

@John T Smith is spot on with the information that you need to supply for someone to help you accurately. However, if it's JS that you are using something like the following could work

if (event.value) event.value = parseFloat(event.value).toPrecision(3) + "%"

-Manan

 

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 ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

I am using adobe acrobat pro on a MacBook 

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 ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

Holy guacamole! Thank you it worked !! Yay!!!

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 ,
Apr 27, 2022 Apr 27, 2022

Copy link to clipboard

Copied

LATEST

Manan had the correct fix

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 ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

There is no need for script, in field properties, select 'Format' tab then select percentage and select number of  decimals.

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 ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

The problem with doing it like that is that it doesn't actually change the field's value, so if you use it later on in another calculation you might get unexpected results.

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 ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

Although, the other solution given above has the same issue, of course... You must not use the Format event if you want to avoid this problem.

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 ,
Apr 20, 2022 Apr 20, 2022

Copy link to clipboard

Copied

I tried solving the problem in the format field before reaching out to the forum  but it didn't work. The script from Manan Joshi worked perfectly! 

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