Copy link to clipboard
Copied
I have used the following code in a pdf document. event.value = ( this.getField("Rent").value / this.getField("Month").value ) * this.getField("Days").value. I have formatted the field for two decimal places. When I total several of these calculations in a later field it is sometimes off by .01. While the field is rounding the number, it is using the actual number with many places after the decimal point in adding multiple fields together.
Formatting controls the appearance of the field data, but the value is the same.
So you need to change the decimal places in the actual field value.
Try this.
var nValue = ...Your calculation...
event.value = Number(util.printf("%0.2f",nValue));
This code code uses the print function to create a string version of the number with the correct number of digits, and then converts it to a number.
From a coding perspective this is easier than trying to use math to cut off the decimal places. Programming p
...Copy link to clipboard
Copied
You must round the calculated value.
Copy link to clipboard
Copied
Formatting controls the appearance of the field data, but the value is the same.
So you need to change the decimal places in the actual field value.
Try this.
var nValue = ...Your calculation...
event.value = Number(util.printf("%0.2f",nValue));
This code code uses the print function to create a string version of the number with the correct number of digits, and then converts it to a number.
From a coding perspective this is easier than trying to use math to cut off the decimal places. Programming purest would have a problem with it.
Copy link to clipboard
Copied
Thank you Thom. This worked the magic I needed.