Math.round() in javascript

     The Math.round() function returns the value of a number rounded to the nearest integer. If the fractional portion of number is 0.5 or greater, the argument is rounded to the next higher integer. If the fractional portion of number is less than 0.5, the argument is rounded to the next lower integer.

     Because round() is a static method of Math, you always use it as Math.round(), rather than as a method of a Math object you created (Math has no constructor).

Syntax

   Math.round(number);
Example

Math.round(19.39); //19

Math.round(19.7); //20

Math.round(-19.04); //-19

Math.round(-19.51); //-20


Example Program:- (Editor)


Editor is Loading...

Advertisement

0 nhận xét:

Đăng nhận xét