Calculate Without Rounding
Copy link to clipboard
Copied
I have five fields I, M, P, S, U that I want to add without rounding into field Total. I have all the fields formatted as number with two decimal places and currency symbol. As example in attached document, I understand the total may be $1,752.946 but I want it to read for print as $1,752.94 and not round up to $1,752.95.
Any help on this please?
Copy link to clipboard
Copied
Change the Format setting of the Total field to None...
Copy link to clipboard
Copied
I did that before, but it insists on rounding up. In any case, I need the Total field to have decimal (2 places) and currency symbol. This is a case of printing the form, not submitting electronically. I print it with round up, and anyone will question why the math does not match. Is there a script that limits calculations to two places without rounding up?
Copy link to clipboard
Copied
There's a difference between rounding a value or truncating a value.
If the resulting value was produced from a calculation that produced many digits after the decimal point, and you only need two decimals to the right of decimal point, then if whatever number to the right of the last significant digit that is 5 (or higher than 5) will automatically round up the number to its left.
If you're not really concerned about precision, then truncating would be a more appropriate term in this case.
Copy link to clipboard
Copied
Removing decimals will always involve rounding, by definition.
So are you saying you want it to always round down?
Copy link to clipboard
Copied
No rounding at all. I simply want to tunicate a number to decimal with 2 places. If it reads $14.256, I would like it to instead read $14.25. No rounding up or down.
Copy link to clipboard
Copied
That's called rounding down. It is a kind of rounding. You're confusing us saying you don't want rounding!
Copy link to clipboard
Copied
Truncating and rounding are the same thing.
Copy link to clipboard
Copied
Subtract 0.005 from the total.
Copy link to clipboard
Copied
Would that be a permanent solution applied as a simplified script in my "Total" field?
Copy link to clipboard
Copied
You don't need a script. Add a invisible field with value -0.005
Copy link to clipboard
Copied
Use a custom format script to display the truncated value. First, use the string value of the fields and then remove everything after the first two decimal points.
Here's one way to do it (there are many):
event.value = event.value.toString().replace(/(^.*\.\d{2}).*$/,"$1");
Use the Acrobat JavaScript Reference early and often

