ITADN

InexactFloat64 not returning the nearest float64

#399Closedthomas-bombrun 创建于 2025-04-24
T
thomas-bombruncommented
With this code : ```go package main import ( "fmt" "github.com/shopspring/decimal" ) func main() { fmt.Println(decimal.NewFromFloat(1.).Div(decimal.NewFromFloat(28.)).InexactFloat64()) // 1/28 in decimal fmt.Println(1. / 28.) // 1/28 in float64 fmt.Println(0.0357142857142857142857142857142857142857142857142857142857) // 1/28 in float64 with deep precision } ``` I get the following output : ``` 0.0357142857142857 0.03571428571428571 0.03571428571428571 ``` I expected to have the first line return the final 1 in my call to InexactFloat64() as it seems to be the nearest float64 representing the true value of 1/28.
关闭于 2025-04-25 1 条评论