6 Replies Latest reply on Nov 1, 2016 8:13 AM by CalicoCat5000

# Stop Automatic Calculation Rounding or set None format category to two decimals?

Hi, how do you stop automatic rounding in a calculation result?  The results field needs to display the actual unrounded number with two decimal points (it is a currency), and I have a simple multiplication calculation script:

var v1 = this.getField("Construction").value;

event.value = v1 * .001;

if ((event.value == 0) && (getField("Construction").valueAsString === "")) event.value = "";

When the format category is set as Number with two decimal places, the result is automatically rounded.  When the format category is set as None, the result is unrounded but there are more than two decimal places.  What should be done to display the actual unrounded number with a maximum of two decimal places?

• ###### 1. Re: Stop Automatic Calculation Rounding or set None format category to two decimals?

Change this line:

event.value = v1 * .001;

To:

event.value = (v1 * .001).toFixed(2);

And also change the Format option to None.

• ###### 2. Re: Stop Automatic Calculation Rounding or set None format category to two decimals?

It's not at all clear to me what you want. You say you want to limit it to two decimal places, but at the same time say that a number format limited to two decimal places isn't what you want. Can you clarify with the following example?:

Field value: 123456

Field value multiplied by 0.001: 123.456

This resulting value should then be displayed as:

A. 123.45

B. 123.46

C. 123.456

D. Something else: _________

Using the toFixed(2) method will give option B, which is what setting the number format to 2 decimals will do.

• ###### 3. Re: Stop Automatic Calculation Rounding or set None format category to two decimals?

Thank you both, and you're right, I didn't fully explain.  We need option A as the result.  I've been googling to try to find the answer but have a feeling I'm not using the correct language when searching.  I've looked for "adobe pro display true value" and variations with  "javascript "unrounded value" "actual value" but there's probably a better term.  Any additional advice to get option A would be appreciated.

• ###### 4. Re: Stop Automatic Calculation Rounding or set None format category to two decimals?

I tried the following but it didn't make a difference:

var v1 = this.getField("Construction").value.toFixed(2);

event.value = (v1 * .001).toFixed(2);

The Construction field is set up as a format category Number with two decimal places (for currency), I tried switching it to format category None and I added  + in front of this.getField but it didn't result in option A.

• ###### 5. Re: Stop Automatic Calculation Rounding or set None format category to two decimals?

Use this code:

event.value = Math.floor(v1/10)/100;

• ###### 6. Re: Stop Automatic Calculation Rounding or set None format category to two decimals?

Thank you!!!