Menu Close

Go – RoundToEven() fucntion in math package in go

Here, We will learn about RoundToEven() fucntion in math package in go.  RoundToEven() is used to get the nearest integer, rounding ties to even.

Function prototype:

func RoundToEven(x float64) float64

Return value:

RoundToEven() function in math package returns
the nearest integer, rounding ties to even.

Example with code:

package main

import (
  "fmt"
  "math"
)

func main() {

  no := math.RoundToEven(1.2)
  fmt.Println(no)

  no = math.RoundToEven(2.7)
  fmt.Println(no)

  no = math.RoundToEven(0.0)
  fmt.Println(no)

  no = math.RoundToEven(-2.9)
  fmt.Println(no)
}

Output:

1
3
0
-3

To learn more about golang, Please refer given below link:

https://www.techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/
Posted in golang, math

Leave a Reply

Your email address will not be published.

Contact Us