package main
import (
"dog/util/val"
"fmt"
"log"
"strconv"
)
func main() {
// 四舍五入
log.Println(strconv.FormatFloat(1.234567, 'f', 3, 64))
// 五舍六入
log.Println(val.Decimal(1.2345, 3))
log.Println(val.Decimal(1.2346, 3))
}
func Decimal(value float64, bit int) float64 {
value, _ = strconv.ParseFloat(fmt.Sprintf("%."+strconv.Itoa(bit)+"f", value), 64)
return value
}
有疑问加站长微信联系(非本文作者)
![](https://static.golangjob.cn/static/img/footer.png?imageView2/2/w/280)