Logo

Programming-Idioms

History of Idiom 81 > diff from v3 to v4

Edit summary for version 4 by :

Version 3

2015-09-01, 21:32:27

Version 4

2015-09-03, 15:52:19

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
y = x.round
y = Math.round(x)
Doc URL
http://ruby-doc.org/core-2.2.3/Float.html#method-i-round