float64减法精度问题

leftluoyi · · 1943 次点击
可以尝试用这个包[https://github.com/shopspring/decimal]() ``` package main import ( "fmt" "github.com/shopspring/decimal" ) func main() { var mtime float64 = 3592345111.6499996000 d := decimal.NewFromFloat(mtime) i := d.IntPart() d2 := decimal.New(i, 0) d3 := d.Sub(d2) fmt.Println(d, "-", d2, "=", d3) } ``` 结果:3592345111.6499996 - 3592345111 = 0.6499996
#1