Skip to main content
Known Participant
November 15, 2021
Answered

Need help with stopping calculation field from rounding

  • November 15, 2021
  • 1 reply
  • 2138 views

Hi,

 

I have a simple calculation field, which is averaging 5 fields together, and i have set the field to a number format with 2 decimal places.  Now I realize that if you click on the number, it shows you the exact number, but I would like to have it display the real value to the 2nd decimal, without adding another decimal (which is the easiest way)

 

I have tried a custom calculation code with the math.round, math.ceil and (num).fixto(2) which I found from a few articles, but nothing is helping, so I was wondering if anyone had any other suggestions to try?

This topic has been closed for replies.
Correct answer Bernd Alheit

hi there so I tried that, and it is rounding the decimal still.

so I have a field with the following custom calculation code:

// Initialize variables
var i, v, num = 0, sum = 0;
// Loop through the input fields
for (i = 1; i <= 13; i++) {
  v = +getField("A" + i).value;
  if (v !== 0) {
  // increment the non-blank/zero field counter
  num++;
  // add the field value to the running total
  sum += v;
  }
}
// Calculate the average
if (num) {
  event.value = sum / num;
} else {
  // All fields are empty, so set to blank
  event.value = "";
}

and set formatting to "none" so for this example the calculation came out to be: 2.7384615

I then created a field with this custom calculation:

event.value = this.getField("Overall Score").value.toFixed(2)

Formatting is set to "none" as well, and when I looked at the value it showed as: 2.74, but when I changed the code to ".toFixed(3)" it displayed the value as 2.738

I am not sure what is going on, or why its still rounding when set to 2.


Try this:

event.value = (this.getField("Overall Score").value - 0.005).toFixed(2);

1 reply

try67
Community Expert
Community Expert
November 15, 2021

Remove the Format option and round the value in your calculation script, using toFixed(2), not fixto(2), which doesn't exist.

Known Participant
November 15, 2021

sorry that's what i meant to put toFixed(2), but I will try that removing formatting

try67
Community Expert
Community Expert
November 16, 2021

Can you share the file in question, please?


> for instance the real number is: 3.01538461, but the field with the script you sent displays this value: 3.03

 

This is not what I'm getting. See: