Logo

Programming-Idioms

History of Idiom 81 > diff from v13 to v14

Edit summary for version 14 by :
New Go implementation by user [mem]

Version 13

2015-11-30, 12:37:31

Version 14

2016-01-02, 14:58:59

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).

Imports
math
Code
x := 0.1
y := int(math.Floor(x + 0.5))
Demo URL
http://play.golang.org/p/mWWdERPVix