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

Help with javascript rounding (2nd attempt)

New Here ,
Dec 12, 2016 Dec 12, 2016

Hi,

I have already tried to get an answer in this thread last month: Help with javascript rounding

I was asked to send the form and was supposed to get the form back with the javascript corrected.. but never got any reply (if someone else would like to take a look at my form I would really appreciate it).

In any case, here is the problem:

I have to add 3 Fields to get a TOTAL.

SUBTOTAL + TAX1 + TAX2 = TOTAL

So here is a real example :

99,50 + 4,975 + 9.925125 = 114,400125 $

The problem is that since the format of the Fields is set to "2 decimals", I get the following:

99,50 + 4,98 + 9,93 = 114,40 $

Evidently, the obvious result should be 114,41 $ (and not 114,40$).

So what I need is the correct script that will correctly round TAX1 and TAX2 to 2 decimals, so that the total is 1 cent more...

Any help is welcomed.

Thanks!

TOPICS
Acrobat SDK and JavaScript , Windows
542
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 ,
Dec 12, 2016 Dec 12, 2016

There's a really good article on rounding decimals at the URL below.

Rounding Decimals in JavaScript

J-

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 ,
Dec 12, 2016 Dec 12, 2016

In the article you mention, the guy says to put the following script:

Number(Math.round(1.005+'e2')+'e-2'); // 1.01

Where do I have to paste this?

As a Custom VALIDATION script? If so, that didn't do anything...

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 ,
Dec 12, 2016 Dec 12, 2016
LATEST

You'd put something like the script above in the calculation script for the total but you'll want to reference your own fields rather than copy and paste the script above. The example in the Acrobat JavaScript documentation under field value gives a good example of how to get a couple of field values, add them, multiply the result by another number and then have the result entered as the field value of a calculation. 

Field properties

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