Logo

Programming-Idioms

History of Idiom 81 > diff from v59 to v60

Edit summary for version 60 by programming-idioms.org:
Restored version 58: Testing restoring with a reason

Version 59

2020-08-10, 23:02:09

Version 60

2020-08-10, 23:03:10

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

Variables
y,x
Variables
y,x
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
Doc URL
https://golang.org/pkg/math/#Floor
Demo URL
http://play.golang.org/p/mWWdERPVix
Demo URL
http://play.golang.org/p/mWWdERPVix