3 Replies Latest reply on Dec 30, 2011 12:27 PM by Ned Murphy

# how to round decimal point to two places

Hi all, I have been tasked with creating a custom "calculator" for a client that uses a specific equation. The client inputs data into two Input Text fields and the result shows up in a dynamic text field. Is there any way I can limit the number of decimal places to two? Here is my code (which works, except for the decimal issue):

function onCalculate()
{
one = Number(number_one);
two = Number(number_two);
result_1 = ((one / 4) * (65 / (1 - 0.25))) + ((two / 0.5) * (65 / (1 - 0.25)));
}

• ###### 1. Re: how to round decimal point to two places

What will often be done is the result is first multiplied by 100, then rounded to an integer, then divided by 100.  So picking up from your last line where you calcvulate the result_1 value...

result_1 = Math.round(result_1*100)/100;

• ###### 2. Re: how to round decimal point to two places

Yay!!!!! Thank you so much!

• ###### 3. Re: how to round decimal point to two places

You're welcome