package main import ( "math/big" "strings" ) func Trunc(a string, prec int) string { newn := strings.Split(a, ".") if prec <= 0 { return newn[0] } if len(newn) < 2 || prec >= len(newn[1]) { return a } return newn[0] + "." + newn[1][:prec] } func main() { a := new(big.Float).SetFloat64(2.0) b := new(big.Float).SetFloat64(3.0) c := new(big.Float).Quo(a, b) println(Trunc(c.Text('g', 512), 1)) }
目前尚无回复