Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method NewFromString and NewFromFloat works differently #289

Open
DarkDrim opened this issue Jun 29, 2022 · 1 comment
Open

Method NewFromString and NewFromFloat works differently #289

DarkDrim opened this issue Jun 29, 2022 · 1 comment

Comments

@DarkDrim
Copy link

DarkDrim commented Jun 29, 2022

Example:

a, _ := decimal.NewFromString("166.6666666666666667")
b := decimal.NewFromFloat(166.6666666666666667)
fmt.Println(a.Equal(b)) // false

println(a.String()) // 166.6666666666666667
println(b.String()) // 166.66666666666666

Play with it:
https://go.dev/play/p/isV9ODqEy5u

The same for:

decimal.NewFromFloatWithExponent(166.6666666666666667, -16)

Question is: why NewFromString and NewFromFloat returns different values?

@baryluk
Copy link

baryluk commented Jul 19, 2022

Because 166.6666666666666667 == 166.66666666666666 for float64.

This is a correct behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants