-
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
BigDecimal invalid support #413
Comments
I'll take a look at this |
@stleary , while this is "working as designed", I do agree with @dybuk87 that we should consider changing the default handling of numbers. What's happening in this example is that the Let me know your thoughts. |
@johnjaylward Haven't looked at the code yet, but this sounds reasonable given that BigNumber is a recent enhancement. |
There is a difference between getBigDecimal and optBigDecimal.
prints:
Why is there a difference? getBigDecimal converts the double to a String and than to a BigDecimal: |
@urfuchs can you open a new issue for this? it's a different problem than the original request |
moved to #438 |
Working as designed. |
Same code, but the output for me is:
I use the 20200518 version |
@borgogelli , I'm not sure I understand what action you are expecting from your comment. Are you confirming the fix worked, or do you expect the behaviour to be different? |
Hi @johnjaylward , both the things. First the output of my code is different from the code posted by @urfuchs . And then I have expected the result to be 72.35 |
The recommendation when using the double myDouble = someComplexCalculation();
JSONObject jo = new JSONObject();
jo.put("myDouble", myDouble);
// ... some other code
someFunction(jo.getBigDecimal("myDouble")); The old method of using the string value of the underlying double did preserve the value when parsed from a string, but it lost some complexities if the double was originally stored from a calculation. PR #453 basically solves the issue for both use cases by preserving the textual representation when parsing (by using a Until #453 is accepted, the expected use would be to do something like (use double myDouble = someComplexCalculation();
JSONObject jo = new JSONObject();
jo.put("myDouble", myDouble);
// ... some other code
someFunction(jo.getBigDecimal("myDouble").setScale(5, RoundingMode.ROUND_HALF_EVEN)); |
Hi,
I think BigDecimal support is misleading in current version, currently json :
new JSONObject(" { "value" : 34300000000000000000000000.14 }").getBigDecimal("value").toPlainString()
will return 34300000000000000000000000 instead of correct value 34300000000000000000000000.14
I found in code
// if we want full Big Number support this block can be replaced with:
// return stringToNumber(string);
if (isDecimalNotation(string)) {
After uncommenting this line support is valid and I believe this should be default instead of current one because there is a lot of situation where you need full precision like money amount, or at least there should be some configuration for json parser.
The text was updated successfully, but these errors were encountered: