数学操作补充工具补充了小数点位数、四舍五入取整等常用的数学操作。
工具加载
import (
"github.com/cnlesscode/gotool/maths"
)
DecimalPlaces32(num float32, places int) (float32, error)
var num32 float32 = 12.3
num32, _ = maths.DecimalPlaces32(num32, 1)
fmt.Printf("num: %v\n", num32)
DecimalPlaces64(num float64, places int) (float64, error)
var num64 float64 = 12000008989.31878887
num64, _ = maths.DecimalPlaces64(num64, 2)
fmt.Printf("num: %v\n", num64)
FloatToString(num float64, places int) string
fmt.Printf("num: %v\n", maths.FloatToString(12000008989.318788, 2))
Round(num float64) int
fmt.Printf("maths.Floor(12.89): %v\n", maths.Round(12.89))