03708a90ef
* api cleaup * updates * wtf * updates * snapshot. * tweaks * snapshot * api tweaks. * updates * updates * updates * changes. * updates * updates * sequence => seq * dont need to use curl, just using wget * fixing examples
32 lines
493 B
Go
32 lines
493 B
Go
package seq
|
|
|
|
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)
|
|
}
|