Logo

Programming-Idioms

History of Idiom 81 > diff from v35 to v36

Edit summary for version 36 by programming-idioms.org:
[Go] +DocURL

Version 35

2016-11-30, 22:50:20

Version 36

2016-12-06, 14:43:23

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