4 Replies Latest reply on Dec 5, 2017 5:41 PM by chloeh74927183

# How do I get my form calculation to round to 2 decimal places?

Hi,

I need my total value amount in my form to display two decimal places. At the moment it shows as .00 no matter what numbers I put in.

The script I am using is this:

(function () {

// Get the field values, as numbers

var v1 = +getField("ccc").value;

var v2 = +getField("ddd").value;

if (v1 !== 0) {

event.value = v1 * v2 * 220;

} else {

event.value = "";

}

})();

• ###### 1. Re: How do I get my form calculation to round to 2 decimal places?

Change that one line to:

event.value = util.printf("%.2f", v1 * v2 * 220);

If that doesn't work, please give examples of the values for the ccc and ddd fields, along with the displayed result.

• ###### 2. Re: How do I get my form calculation to round to 2 decimal places?

Hi, thanks for your reply but that didn't work.

ccc is calculated by:

(function () {

// Get the field values, as numbers

var v1 = +getField("aaa").value;

var v2 = +getField("bbb").value;

if (v2 !== 0) {

event.value = v1 / v2 ;

} else {

event.value = "";

}

})();

So i have aaa, bbb, ccc, ddd, eee. On my phone in Reader when these equal 65, 1.35, 48, and 25 respectively I get eee to equal 264,814.8

On my desktop when these same values are entered eee displays as 264,000.00

• ###### 3. Re: How do I get my form calculation to round to 2 decimal places?

What do you have set as a format on the calculated fields? I'd suggest removing all formatting. Then let us know what you  got.

Sounds like Reader is having an issue. Could be extra code that's in there.

• ###### 4. Re: How do I get my form calculation to round to 2 decimal places?

Hi

I had the formatting set to:

Number

Decimal Places: 2

Separator Style: 1,234.56

Currency Symbol: None

and that's it.

I've just reset them all to "none" and it's still not working.