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

JSON-deserialization from decimal.MaxValue (as double) should not fail #386

Merged
merged 2 commits into from Apr 19, 2024

Conversation

Corniel
Copy link
Collaborator

@Corniel Corniel commented Apr 19, 2024

When Amount.Max is serialized to JSON, its gets the value 7.922816251426434E+28. This value can not be deserialized, because of rounding/precision issues, that can be demonstrated without any JSON serialization:

var dbl = (double)decimal.MaxValue;
var dec = (decimal)dbl;

This code fails on the second line saying that dbl is either too big or too small.

This p.r. adds some forgiveness when casting back from doubles to decimals, that prevents this issue from occurring.

@Corniel Corniel added the bug label Apr 19, 2024
Copy link
Collaborator

@Sjaaky Sjaaky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Corniel Corniel merged commit 8e359c8 into master Apr 19, 2024
2 checks passed
@Corniel Corniel deleted the decimal-max-value branch April 19, 2024 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants