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

Calculate Without Rounding

New Here ,
Aug 22, 2021 Aug 22, 2021

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?

TOPICS
PDF forms
2.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 ,
Aug 22, 2021 Aug 22, 2021

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

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 ,
Aug 22, 2021 Aug 22, 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?

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 ,
Aug 22, 2021 Aug 22, 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. 

 

 

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 ,
Aug 23, 2021 Aug 23, 2021

Removing decimals will always involve rounding, by definition.

So are you saying you want it to always round down?

 

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 ,
Aug 23, 2021 Aug 23, 2021

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.

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
LEGEND ,
Aug 23, 2021 Aug 23, 2021

That's called rounding down. It is a kind of rounding. You're confusing us saying you don't want rounding! 

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 ,
Aug 23, 2021 Aug 23, 2021

Truncating and rounding are the same thing.

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 ,
Aug 22, 2021 Aug 22, 2021

Subtract 0.005 from the total.

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 ,
Aug 23, 2021 Aug 23, 2021

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

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 ,
Aug 23, 2021 Aug 23, 2021

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

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 ,
Aug 23, 2021 Aug 23, 2021
LATEST

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

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