Logo

Programming-Idioms

History of Idiom 81 > diff from v15 to v16

Edit summary for version 16 by :
[Go] Proper import

Version 15

2016-01-02, 18:51:57

Version 16

2016-01-03, 13:22:52

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
Imports
import "math"
Code
x := 0.1
y := int(math.Floor(x + 0.5))
Code
y := int(math.Floor(x + 0.5))
Demo URL
http://play.golang.org/p/mWWdERPVix
Demo URL
http://play.golang.org/p/mWWdERPVix