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

NewFromFloat trouble #121

Open
font1k opened this issue Oct 16, 2022 · 3 comments
Open

NewFromFloat trouble #121

font1k opened this issue Oct 16, 2022 · 3 comments

Comments

@font1k
Copy link

font1k commented Oct 16, 2022

Why is the float64 value equal to 1.15 created in the money type as 1.14?
The link below shows an example of the supposed error:
https://go.dev/play/p/Z64XrP8LdTc

@vivl4725
Copy link

vivl4725 commented Oct 17, 2022

@jasonharrison, you could use decimal to fix this problem
https://go.dev/play/p/HUMiR2-5AOb

@kotaroyamazaki
Copy link
Contributor

kotaroyamazaki commented Nov 8, 2022

I have the same issue.

@jasonharrison, you could use decimal to fix this problem https://go.dev/play/p/HUMiR2-5AOb

@vivl4725
I guess this solution doesn't make sense for those who want to use go-money.

@totemcaf
Copy link
Contributor

The problem is that the binary representation of 1.15 is closer to 114.99999999999999

This can solved by adding a small "epsilon" value to the parsed value.

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

4 participants