Round a decimal number

mjocasio23
Tera Expert

I having a problem rounding a number to a certain precision ....

I gettting a value as a string from a form field , then I convert that number to a foat and then applied the round function.... but it does not work as I want it...

var temp   = parseFloat(g_form.getValue('substance_allowance'));

temp = Math.round(temp).toFixed(2); it wont work to rund the value two decimals places if a situation applies.... what it does           it rounds up but it moves the decimals two places to the right.

8 REPLIES 8

Shishir Srivast
Mega Sage

You want to round the figure or want to convert to 2 decimal?


I want round any length whole number which it shouldn't be affected containing a fractional part greater than two decimals to this precision rounded up.


Shishir Srivast
Mega Sage

can we try like.



var temp   = Math.round(parseFloat(g_form.getValue('substance_allowance')));


This rounds to the nearest whole number...... I want to           hold to 2 decimals places and rounded.