Skip to content

[BUG] 使用 UseBigDecimalForDoubles 解析浮点数,结果为 Float,精度下降 #3488

Open
@X-czh

Description

@X-czh

问题描述

使用 UseBigDecimalForDoubles 解析浮点数,结果为 Float,精度下降。

相关背景:我们在做 fastjson1->2 的升级,fastjson1 中浮点数解析默认为 BigDecimal,fastjson2 升级后希望对齐避免数据问题,但是加了 UseBigDecimalForDoubles & UseBigDecimalForFloats 后出现非预期行为。

环境信息

  • OS信息: macOS 15.3.1
  • JDK信息: OpenJDK 17.0.14
  • 版本信息:fastjson2 2.0.57

重现步骤

String str = "{\"val\":0.06451612903225806}";
JSONObject object = JSON.parseObject(str, JSONReader.Feature.UseBigDecimalForDoubles);
Object val = object.get("val");
System.out.println(object);
assertEquals(BigDecimal.class, val.getClass());

期待的正确结果

预期:{"val":0.06451612903225806},类型为 BigDecimal
实际:{"val":0.06451613},类型为 Float

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions