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 from 0. Moreover, this function is defined under the time package. Here, you need to import the “time” package in order to use these functions.

**Syntax:**

func (d Duration) Round(m Duration) Duration

Here, d is the duration of time that will be rounded and m is the closest multiple.

**Return value:** It returns maximum (or minimum) duration if the outcome surpasses the maximum (or minimum) value that could be stored in a duration. But if m is less than or equal to 0 then it returns unaltered ‘d’.

**Example 1:**

`// Golang program to illustrate the usage of ` `// Round() function ` ` ` `// Including main package ` `package main ` ` ` `// Importing fmt and time ` `import ( ` ` ` `"fmt"` ` ` `"time"` `) ` ` ` `// Calling main ` `func main() { ` ` ` ` ` `// Defining duration ` ` ` `// of Round method ` ` ` `d, _ := ` `time` `.ParseDuration(` `"5m7s"` `) ` ` ` ` ` `// Prints rounded d ` ` ` `fmt.Printf(` `"Rounded d is : %s"` `, ` ` ` `d.Round(6*` `time` `.Second)) ` `} ` |

*chevron_right*

*filter_none*

**Output:**

Rounded d is : 5m6s

Here, ‘d’ is rounded to the closest multiple of m.

**Example 2:**

`// Golang program to illustrate the usage of ` `// Round() function ` ` ` `// Including main package ` `package main ` ` ` `// Importing fmt and time ` `import ( ` ` ` `"fmt"` ` ` `"time"` `) ` ` ` `// Calling main ` `func main() { ` ` ` ` ` `// Defining duration of Round method ` ` ` `d, _ := ` `time` `.ParseDuration(` `"3m73.671s"` `) ` ` ` ` ` `// Array of m ` ` ` `R := []` `time` `.Duration{ ` ` ` `time` `.Microsecond, ` ` ` `time` `.Second, ` ` ` `3 * ` `time` `.Second, ` ` ` `9 * ` `time` `.Minute, ` ` ` `} ` ` ` ` ` `// Using for loop and range to ` ` ` `// iterate over an array ` ` ` `for` `_, m := range R { ` ` ` ` ` `// Prints rounded d of all ` ` ` `// the items in an array ` ` ` `fmt.Printf(` `"Rounded(%s) is : %s\n"` `, ` ` ` `m, d.Round(m)) ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

**Output:**

Rounded(1µs) is : 4m13.671s Rounded(1s) is : 4m14s Rounded(3s) is : 4m15s Rounded(9m0s) is : 0s

Here, an array of ‘d’ is formed first then a range is used in order to iterate over all the values of d. And at last Round() method is used to print all the rounded values of d.

## Recommended Posts:

- time.Sleep() Function in Golang With Examples
- time.Time.Year() Function in Golang with Examples
- time.ParseDuration() Function in Golang With Examples
- time.After() Function in Golang With Examples
- time.Tick() Function in Golang With Examples
- time.NewTimer() Function in Golang With Examples
- time.Weekday() Function in Golang With Examples
- time.Since() Function in Golang With Examples
- time.Until() Function in Golang With Examples
- time.Hours() Function in Golang With Examples
- time.Microseconds() Function in Golang With Examples
- time.Milliseconds() Function in Golang With Examples
- time.Minutes() Function in Golang With Examples
- time.Nanoseconds() Function in Golang With Examples
- time.Seconds() Function in Golang With Examples
- time.String() Function in Golang With Examples
- time.Truncate() Function in Golang With Examples
- time.FixedZone() Function in Golang With Examples
- time.LoadLocation() Function in Golang With Examples
- time.Month.String() Function in Golang With Examples

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.