代码演示
package main
import (
"fmt"
"github.com/shopspring/decimal"
)
func main() {
var dd decimal.Decimal
f := 12.435235235
// 两种方法自行选用
dd = decimal.NewFromFloatWithExponent(f, -2)
cc := dd.Round(2)
fmt.Println(dd)
fmt.Println(cc)
}
结果演示