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

Adding a script to limit to 2 decimal points

New Here ,
Apr 19, 2022 Apr 19, 2022

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. 

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

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

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

@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

 

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

I am using adobe acrobat pro on a MacBook 

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

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

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

Manan had the correct fix

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

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

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

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.

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

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.

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

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! 

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