-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
JSONObject.objectToBigDecimal precision errors when parsing doubles #531
Comments
@Bohlski which version of the library is currently giving you the issue, the master branch or the latest release on Maven? |
@johnjaylward The latest release on Maven |
Do you have a test case we can use to reproduce the issue?
…On Wed, Jun 24, 2020, 03:38 Bohlski ***@***.***> wrote:
@johnjaylward <https://github.com/johnjaylward> The latest release on
Maven
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#531 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC5VV7JNBEM5UBIRTKFQNDRYGUQLANCNFSM4OFN4OBA>
.
|
Looks to me like any use of the constructor on a decimal will give the extra unwanted precision digits. But I guess I can give a boiled down version of my current test:
This fails with output Within the newer versions (post version 20180813, I believe), |
@Bohlski We will look into these questions:
|
Add test result to confirm that stleary#531 is working in latest version.
I used the test case provided and confirmed that the changes in latest master branch correct the issue. |
When parsing doubles the method uses the BigDecimal(double) constructor, which can have unpredictable results as stated in the docs: https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#BigDecimal(double)
It is instead preferred to use BigDecimal.valueOf(double)
https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#valueOf(double)
This lead to a few precision errors on my end, when updating from an older version of this library.
The text was updated successfully, but these errors were encountered: