go-chart/sequence/util.go
Will Charczuk c0fc2baa50 updates
2017-05-01 22:18:52 -07:00

32 lines
498 B
Go

package sequence
import "math"
func round(input float64, places int) (rounded float64) {
if math.IsNaN(input) {
return 0.0
}
sign := 1.0
if input < 0 {
sign = -1
input *= -1
}
precision := math.Pow(10, float64(places))
digit := input * precision
_, decimal := math.Modf(digit)
if decimal >= 0.5 {
rounded = math.Ceil(digit)
} else {
rounded = math.Floor(digit)
}
return rounded / precision * sign
}
func f64i(value float64) int {
r := round(value, 0)
return int(r)
}