Live Forms Latest - This documentation is for Live Forms 9.0. Not for you? Earlier documentation is available too.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Let's say you have a Time Sheet where you collect the number of hours worked per day and total them in a Line Total field. Your form consists of Number controls for the hours and a Number control for the total. When testing your form, you enter values with decimal points and notice the total unexpectedly calculates to a number with many decimal places.

This is JavaScript behavior when calculating decimal point addition. 
Method 1: Use the built-in toFixed(n) function to truncate the result to n number of decimal places as shown in the rule below:
 
Section
Column
Code Block
var x;
x = (testone.value + testtwo.value + testthree.value + testfour.value + testfive.value + testsix.value);
LineTotal.value = x.toFixed(2);
Column


Method 2: You can also round numbers using the round function in the Visual Rule Builder in the format:

Code Block
round(num, decimal digits)

Method 3: Another approach would be to assign Patterns that limit the number of decimal places.

...