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] BigDecimal 0.123456789012345678 在 JSONWriter.Feature.BrowserCompatible 下不是输出字符串 #2283

Closed
jaconliang opened this issue Mar 2, 2024 · 2 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@jaconliang
Copy link

问题描述

数字0.123456789012345678在JavaScript不能精确表达,但是BigDecimal 0.123456789012345678 在 JSONWriter.Feature.BrowserCompatible 下不是输出字符串而是直接输出数字。

环境信息

请填写以下信息:

  • 版本信息:Fastjson2 2.0.47

重现步骤

下面代码输出结果是:{"num":0.123456789012345678},期望的结果是:{"num":"0.123456789012345678"}

        BigDecimal num = new BigDecimal("0.123456789012345678");
        JSONObject jsonObj = new JSONObject();
        jsonObj.put("num", num);
        System.out.println(jsonObj.toString(JSONWriter.Feature.BrowserCompatible));

期待的正确结果

期望正确输出:{"num":"0.123456789012345678"}

相关日志输出

附加信息

@jaconliang jaconliang added the bug Something isn't working label Mar 2, 2024
@wenshao
Copy link
Member

wenshao commented Mar 3, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.48-SNAPSHOT/
问题已修复,请帮忙用2.0.48-SNAPSHOT版本帮忙验证,2.0.48版本预计在3月底前发布。

@wenshao wenshao added this to the 2.0.48 milestone Mar 3, 2024
@wenshao wenshao added the fixed label Mar 3, 2024
@wenshao
Copy link
Member

wenshao commented Mar 25, 2024

@wenshao wenshao closed this as completed Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants