[ https://issues.apache.org/jira/browse/GROOVY-7665?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14997380#comment-14997380 ]
ASF GitHub Bot commented on GROOVY-7665: ---------------------------------------- GitHub user jwagenleitner opened a pull request: https://github.com/apache/incubator-groovy/pull/183 GROOVY-7665 - JsonSlurperCharSource decimal parsing producing unexpected results Commit 842bcd4e23fefdf5b5e17d8d91af50e1ce565096 introduced the `BigDecimal` return types and reused some of the original parsing methods. However, in this case I think it makes more sense to just let `BigDecimal` parse the text since converting first to a double can cause some odd results. You can merge this pull request into a Git repository by running: $ git pull https://github.com/jwagenleitner/incubator-groovy GROOVY-7665 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/incubator-groovy/pull/183.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #183 ---- commit 8d17cc10559c69eb93bb7aa39a9f101bcd3296e5 Author: John Wagenleitner <john.wagenleit...@gmail.com> Date: 2015-11-09T21:13:20Z GROOVY-7665 - JsonSlurperCharSource decimal parsing producing unexpected results ---- > JsonSlurperCharSource decimal parsing producing unexpected results > ------------------------------------------------------------------ > > Key: GROOVY-7665 > URL: https://issues.apache.org/jira/browse/GROOVY-7665 > Project: Groovy > Issue Type: Bug > Components: JSON > Affects Versions: 2.4.5 > Reporter: John Wagenleitner > Priority: Minor > > When using the JsonParserType.CHARACTER_SOURCE decimal numbers are first > parsed to double value and that value is used to construct the BigDecimal to > return. This can produce some unexpected results. > For example: > {code} > import groovy.json.* > def parser = new JsonSlurper().setType(JsonParserType.CHARACTER_SOURCE) > def json = parser.parseText('{"num": 123.40}') > assert json.num instanceof BigDecimal > assert 123.40G == json.num > {code} > Fails with: > {code} > Assertion failed: > assert 123.40G == json.num > | | | > | | 123.400000000000005684341886080801486968994140625 > | [num:123.400000000000005684341886080801486968994140625] > false > at Script1.run(Script1.groovy:8) > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)