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

[BUG]小数点后超过38位后,json解析数据错误 #269

Closed
liuliu-miao opened this issue May 17, 2022 · 3 comments
Closed

[BUG]小数点后超过38位后,json解析数据错误 #269

liuliu-miao opened this issue May 17, 2022 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@liuliu-miao
Copy link

liuliu-miao commented May 17, 2022

问题描述

简要描述您碰到的问题。
解析json为小数时,小数位超过38位时数据解析错误。
String jsonStr="{"test_prr":2.9900000000000002131628207280300557613372802734375}";

环境信息

请填写以下信息:

  • OS信息: [e.g.:MacOS 12.3.1]
  • JDK信息: [e.g.:zulu8_jdk8.0.312]
  • 版本信息:[e.g.:Fastjson2 2.0.3]

重现步骤

//可在此输入示例代码
 String jsonStr="{\"test_prr\":2.9900000000000002131628207280300557613372802734375}";
        JSONObject json = JSON.parseObject(jsonStr, JSONReader.Feature.UseBigDecimalForDoubles);
        BigDecimal val = json.getBigDecimal("test_prr");
        System.out.println(val.doubleValue());
        System.out.println(json.toJSONString());
        System.out.println( JSON.toJSONString(json));

错误结果:

3.287119106202786E-11

当小数位少于或等于38位时,输出结果为保留两位小数结果

2.99

期待的正确结果

对您期望发生的结果进行清晰简洁的描述。
2.9900000000000002131628207280300557613372802734375

相关日志输出

请复制并粘贴任何相关的日志输出。

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。

@liuliu-miao liuliu-miao added the bug Something isn't working label May 17, 2022
@liuliu-miao liuliu-miao changed the title [BUG]小数点后超过38位后,json解析失败 [BUG]小数点后超过38位后,json解析数据错误 May 17, 2022
wenshao added a commit that referenced this issue May 17, 2022
@wenshao wenshao added this to the 2.0.4 milestone May 17, 2022
@wenshao
Copy link
Member

wenshao commented May 17, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/

问题已经修复,请帮忙用 2.0.4-SNAPSHOT 版本验证,2.0.4版本预计在5月22日前发布

@liuliu-miao
Copy link
Author

已修复,辛苦了。

@wenshao
Copy link
Member

wenshao commented May 21, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.4
问题已经在2.0.4版本中修复,请用新版本

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants