Logo

Programming-Idioms

History of Idiom 81 > diff from v6 to v7

Edit summary for version 7 by :

Version 6

2015-09-05, 14:01:42

Version 7

2015-09-05, 17:10:43

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 = floor (x + 1/2)
Comments bubble
Haskell would round towards nearest ∈ℤ2 rather than +∞
Doc URL
http://hackage.haskell.org/package/base/docs/Prelude.html#v:floor