2
0

number.go 248 B

123456789101112
  1. package sentio
  2. import "math"
  3. func round(num float64) int {
  4. return int(num + math.Copysign(0.5, num))
  5. }
  6. func ToFixed(num float64, precision int) float64 {
  7. output := math.Pow(10, float64(precision))
  8. return float64(round(num*output)) / output
  9. }