diff --git a/integer/integer.go b/integer/integer.go index e4e740ca..e0811e83 100644 --- a/integer/integer.go +++ b/integer/integer.go @@ -16,6 +16,8 @@ limitations under the License. package integer +import "math" + // IntMax returns the maximum of the params func IntMax(a, b int) int { if b > a { @@ -65,9 +67,7 @@ func Int64Min(a, b int64) int64 { } // RoundToInt32 rounds floats into integer numbers. +// Deprecated: use math.Round() and a cast directly. func RoundToInt32(a float64) int32 { - if a < 0 { - return int32(a - 0.5) - } - return int32(a + 0.5) + return int32(math.Round(a)) } diff --git a/integer/integer_test.go b/integer/integer_test.go index e9f58688..f2988ead 100644 --- a/integer/integer_test.go +++ b/integer/integer_test.go @@ -233,6 +233,10 @@ func TestRoundToInt32(t *testing.T) { num: 0, exp: 0, }, + { + num: 0.49999999999999994, + exp: 0, + }, } for i, test := range tests {