contents   index   previous   next



Math.round()

syntax:

Math.round(x)

where:

x - a number.

 

return:

number - value that is closest to the argument and is equal to a mathematical integer. X is rounded up if its fractional part is equal to or greater than 0.5 and is rounded down if less than 0.5.

 

description:

The value of Math.round(x) is the same as the value of Math.floor(x+0.5), except when x is *0 or is less than 0 but greater than or equal to -0.5; for these cases Math.round(x) returns *0, but Math.floor(x+0.5) returns +0.

 

see:

Math.floor()

 

example:

//Return a mathematical integer:

function compute_int(x)

{

   return Math.round(x)

}

//If the argument is NaN, the result is NaN

//If the argument is already an integer 

//such as any of the

//following values: -0, +0, 4, 9, 8; 

//then the result is the

//argument itself.

//If the argument is .2, then the result is 0.

//If the argument is 3.5, then the result is 4

//Note: Math.round(3.5) returns 4, 

//but Math.round(-3.5) returns -3.

 


Math.sin()