go-chart/seq/util.go

33 lines
493 B
Go
Raw Normal View History

2017-05-12 17:17:43 -04:00
package seq
2017-05-02 01:18:52 -04:00
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)
}