round.go (460B)
1 package sunrise 2 3 import "math" 4 5 // DefaultPlaces specifies the default precision for rounding. 6 const DefaultPlaces = 5 7 8 // Round takes the provided float and rounds it to the specified number of 9 // decimal places. This function is adapted from user korya on GitHub 10 // (https://gist.github.com/DavidVaini/10308388#gistcomment-1391788). 11 func Round(f float64, places int) float64 { 12 shift := math.Pow(10, float64(places)) 13 return math.Floor(f*shift+.5) / shift 14 }