Copy link to clipboard
Copied
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?
Use this code:
event.value = Math.floor(v1/10)/100;
Copy link to clipboard
Copied
Change this line:
event.value = v1 * .001;
To:
event.value = (v1 * .001).toFixed(2);
And also change the Format option to None.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Use this code:
event.value = Math.floor(v1/10)/100;
Copy link to clipboard
Copied
Thank you!!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now