Round off decimal values using JS

Round off decimal values using JS

JS => There are four functions available to round off a decimal value
1) Exact round off ( if x > 0.5 then taken as x=1 and x < 0.5 then taken as x=0 )
2) Rounded up to nearest integer ( if x > 0 then taken as x=1 and x < 0 then taken as x=0 )
3) Rounded down to nearest integer ( if x > 1 then taken as x=1 and x < 1 then taken as x=0 )
4) Round off to given precision of decimal points

1) syntax: Math.round(number);
Example:

 

2) syntax: Math.ceil(number);
Example:

 

3) syntax: Math.floor(number);
Example:

 

4) syntax: element.toFixed(precision); precision=> 0 to 99
Example:

 

 

Leave a Reply

%d bloggers like this: