Skip to content

[BUG] 使用 UseBigDecimalForDoubles 解析浮点数,小数点漂移 #3382

@X-czh

Description

@X-czh

问题描述

使用 UseBigDecimalForDoubles 解析浮点数,小数点漂移

环境信息

  • OS信息: macOS 15.3.1
  • JDK信息: OpenJDK 17.0.14
  • 版本信息:Fastjson2 2.0.56

重现步骤

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

期待的正确结果

  • 预期:{"val":0.00002503705945562304}
  • 实际:{"val":2.503705945562304}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions