Logo

Programming-Idioms

History of Idiom 81 > diff from v37 to v38

Edit summary for version 38 by programming-idioms.org:
New JS implementation by user [programming-idioms.org]

Version 37

2017-08-21, 12:16:03

Version 38

2017-10-16, 09:35:31

Idiom #81 Round floating point number to integer

Declare integer y and initialize it with the rounded value of floating point number x .
Ties (when the fractional part of x is exactly .5) must be rounded up (to positive infinity).

Idiom #81 Round floating point number to integer

Declare integer y and initialize it with the rounded value of floating point number x .
Ties (when the fractional part of x is exactly .5) must be rounded up (to positive infinity).

Code
var y = Math.round(x);
Doc URL
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round