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

Field Calculation adding decimal places where it shouldn't

New Here ,
Jun 20, 2023 Jun 20, 2023

Copy link to clipboard

Copied

On the attached form there is some wierd rounding issues occuring that I can't figure out. 

Line 7 and 8 are both numbers to two decimal places. 

 

Line 9 uses the following formula:

var a = this.getField("A").value;

var b = this.getField("B").value;

if (a !=="" || b !==""){

event.value = b-a;

} else {

event.value ="";

}

 

value of a is 5,112,068.82

value of b is 5,184,600.47

 

For some reason line 9 calculates to 72531.64999999944.

I am having the same issues with line 10. 

 

Can someone please take a look and help me out? I attached the PDF for reference. 

 

TOPICS
Acrobat SDK and JavaScript , Windows

Views

241

Translate

Translate

Report

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 ,
Jun 20, 2023 Jun 20, 2023

Copy link to clipboard

Copied

LATEST
The reason why this is happening is complicated (you can google "JavaScript
floating point precision" to get a better understanding), but the solution
is simple.
Change this line:
event.value = b-a;
To:
event.value = (b-a).toFixed(2);

Votes

Translate

Translate

Report

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