Excel07SaxReader中,对于小数类型,增加精度判断(issue#IB0EJ9@Gitee)

This commit is contained in:
Looly
2024-11-19 16:42:29 +08:00
parent 812c75158e
commit 4437b63ee5
4 changed files with 38 additions and 3 deletions

View File

@@ -0,0 +1,25 @@
package cn.hutool.json;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class Issue3790Test {
@Test
void bigDecimalToStringTest() {
BigDecimal bigDecimal = new BigDecimal("0.01");
bigDecimal = bigDecimal.setScale(4, RoundingMode.HALF_UP);
Dto dto = new Dto();
dto.remain = bigDecimal;
final String jsonStr = JSONUtil.toJsonStr(dto, JSONConfig.create().setStripTrailingZeros(false));
Assertions.assertEquals("{\"remain\":0.0100}", jsonStr);
}
static class Dto {
public BigDecimal remain;
}
}