alibaba / alibaba/fastjson2

[BUG]fastjson2 2.0.64 使用getBigDecimal存在精度丢失问题

Open
#7,794 0 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 问题描述
fastjson2 2.0.64 使用getBigDecimal存在精度丢失问题

### 环境信息
- OS信息: Mac Tahoe 26.1
- JDK信息:OpenJDK 21.0.7
- 版本信息:2.0.64

### 重现步骤
public static void main(String[] args) {
JSONObject value = new JSONObject().fluentPut("value", 0.00054797);
System.out.println(value.getBigDecimal("value"));
}
输出:0.0005479699999999999,与预期0.00054797不符。

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the example with JSONObject.fluentPut and getBigDecimal on fastjson2 2.0.64, then trace the implementation of those methods to find where the decimal value loses precision. Add a regression test covering 0.00054797 and verify that the returned value matches the expected decimal representation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.