3 Replies Latest reply on Dec 12, 2016 6:45 PM by Joel_Geraci

# Help with javascript rounding (2nd attempt)

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!

• ###### 1. Re: Help with javascript rounding (2nd attempt)

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

J-

• ###### 2. Re: Help with javascript rounding (2nd attempt)

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

• ###### 3. Re: Help with javascript rounding (2nd attempt)

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.