math.Round() Function in Golang With Examples Last Updated : 13 Apr, 2020 Comments Improve Suggest changes Like Article Like Report 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 integer(rounding half away from zero) with the help of Round() 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 Round() function. Syntax: func Round(a float64) float64 If you pass -Inf or +Inf in this function like Round(-Inf) or Round(+Inf), then this function will return -Inf or +Inf. If you pass -0 or +0 in this function like Round(-0) or Round(+0), then this function will return -0 or +0. If you pass NaN in this function like Round(NaN), then this function will return NaN. Example 1: C // Golang program to illustrate how to // round off the given number to the // nearest integer package main import ( "fmt" "math" ) // Main function func main() { // Finding the nearest integer // of the given numbers // Using Round() function res_1 := math.Round(36.98) res_2 := math.Round(-100.98) res_3 := math.Round(math.Inf(-1)) res_4 := math.Round(math.NaN()) res_5 := math.Round(math.Inf(1)) // Displaying the result fmt.Printf("Result 1: %.1f", res_1) fmt.Printf("\nResult 2: %.1f", res_2) fmt.Printf("\nResult 3: %.1f", res_3) fmt.Printf("\nResult 4: %.1f", res_4) fmt.Printf("\nResult 5: %.1f", res_5) } Output: Result 1: 37.0 Result 2: -101.0 Result 3: -Inf Result 4: NaN Result 5: +Inf Example 2: C // Golang program to illustrate how to // round off the given number to the // nearest integer package main import ( "fmt" "math" ) // Main function func main() { // Finding the nearest integer // of the given numbers // Using Round() function nvalue_1 := math.Round(49.89) nvalue_2 := math.Round(-4.567) // Finding sum of the given numbers res := nvalue_1 + nvalue_2 fmt.Printf("%.2f + %.2f = %.2f", nvalue_1, nvalue_2, res) } Output: 50.00 + -5.00 = 45.00 Comment More infoAdvertise with us Next Article math.Round() Function in Golang With Examples K Kirti_Mangal Follow Improve Article Tags : Go Language Golang-Math Similar Reads 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 nee 2 min read math.Pow() 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 find the base-a exponential of b(a**b)with the help of Pow() function provided by the math package. So, you need to add a math package i 3 min read math.Remainder() 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 find the remainder or the IEEE 754 floating-point remainder of a/b with the help of Remainder() function provided by the math package. S 2 min read math.Jn() 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 find the order-n Bessel function of the first kind with the help of Jn() function provided by the math package. So, you need to add a ma 2 min read time.Round() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Round() function in Go language is used to find the outcome of rounding the stated duration 'd' to the closest multiple of 'm' duration. Here, the rounding manner for middle values is to round far off f 2 min read math.Dim() 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. Dim() function provided by the math package return the maximum of a-b or 0. So, to access this function you need to add a math package in your p 2 min read math.Inf() 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 find positive infinity (if sign >= 0) or negative infinity (if sign < 0) with the help of the Inf() function provided by the math 2 min read math.Gamma() 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 find the Gamma function the given value with the help of the Gamma() function provided by the math package. So, you need to add a math p 2 min read math.Hypot 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 find the hypotenuse, i.e., Sqrt(a*a + b*b) with the help of Hypot() function provided by the math package. So, you need to add a math pa 2 min read ring.Len() Function in Golang With Examples ring.Len() function in Golang computes the number of components(elements) in ring(a circular list) r. It executes in time corresponding to the number of components(elements). Syntax: func (r *Ring) Len() int It returns Integer. Example 1: C // Golang program to illustrate // the ring.Len() function 1 min read Like