math.RoundToEven() Function in Golang With Examples
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You can round off the given number to the nearest even integer with the help of RoundToEven() function provided by the math package. So, you need to add a math package in your program with the help of the import keyword to access the RoundToEven() function.
func RoundToEven(a float64) float64
- If you pass -Inf or +Inf in this function like RoundToEven(-Inf) or RoundToEven(+Inf), then this function will return -Inf or +Inf.
- If you pass -0 or +0 in this function like RoundToEven(-0) or RoundToEven(+0), then this function will return -0 or +0.
- If you pass NaN in this function like RoundToEven(NaN), then this function will return NaN.
Result 1: 46.0 Result 2: -120.0 Result 3: -Inf Result 4: NaN Result 5: +Inf
60.00 + -8.00 = 52.00