How do I round a number after the decimal?
When working with calculations in iFormBuilder, you may want to round your results to a certain amount of numbers following the decimal point. To round your calculations after the decimal, please follow the instructions below.
PLEASE NOTE: In order for this functionality to work as expected, you'll need to use either a Text or Text Area element for the elements used to make the calculation. We recommend changing the keyboard type to Number and Punctuation under the Element Properties tab.
Also, if you want any of the elements to be "read-only", please use the Read-Only element type and not a Text element marked as "read-only".
STEP 1. Add four Text elements to your form (three elements to be used for the calculation and a fourth to perform the calculation).
In this example, the data column names of the elements will be as followed:
PLEASE NOTE: Be sure to set each of the elements used in the calculation to an empty string (Ex. field_1=""). This will ensure the fields reset with each new record.
(Number(field_1) * Number(field_2) - Number(field_3)).toFixed(2)
This will round the calculation to two numbers after the decimal. If you'd like to display three numbers after the decimal simply change the function toFixed(3) and so on.
STEP 3. Test it out on your device.
You'll see the calculation is rounded to two numbers after the decimal.
Please use the below Form Package as an example. It also includes an additional field for basic addition.