Skip to main content
Participant
August 22, 2021
Question

Calculate Without Rounding

  • August 22, 2021
  • 3 replies
  • 2987 views

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?

This topic has been closed for replies.

3 replies

Thom Parker
Community Expert
Community Expert
August 23, 2021

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");

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Bernd Alheit
Community Expert
Community Expert
August 23, 2021

Subtract 0.005 from the total.

Participant
August 23, 2021

Would that be a permanent solution applied as a simplified script in my "Total" field?

Bernd Alheit
Community Expert
Community Expert
August 23, 2021

You don't need a script. Add a invisible field with value -0.005

try67
Community Expert
Community Expert
August 22, 2021

Change the Format setting of the Total field to None...

Participant
August 23, 2021

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?

ls_rbls
Community Expert
Community Expert
August 23, 2021

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.