mirror of
				https://gitee.com/dromara/hutool.git
				synced 2025-11-01 00:46:56 +08:00 
			
		
		
		
	Excel07SaxReader中,对于小数类型,增加精度判断(issue#IB0EJ9@Gitee)
This commit is contained in:
		| @@ -2,12 +2,13 @@ | ||||
| # 🚀Changelog | ||||
|  | ||||
| ------------------------------------------------------------------------------------------------------------- | ||||
| # 5.8.34(2024-11-15) | ||||
| # 5.8.34(2024-11-19) | ||||
|  | ||||
| ### 🐣新特性 | ||||
| * 【http   】      增加Windows微信浏览器识别(issue#IB3SJF@Gitee) | ||||
| * 【core   】      ZipUtil.unzip增加编码容错(issue#I3UZ28@Gitee) | ||||
| * 【core   】      Calculator兼容`x`字符作为乘号(issue#3787@Github) | ||||
| * 【poi    】      Excel07SaxReader中,对于小数类型,增加精度判断(issue#IB0EJ9@Gitee) | ||||
|  | ||||
| ### 🐞Bug修复 | ||||
| * 【core   】      修复DateUtil.rangeToList中step小于等于0时无限循环问题(issue#3783@Github) | ||||
|   | ||||
							
								
								
									
										25
									
								
								hutool-json/src/test/java/cn/hutool/json/Issue3790Test.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								hutool-json/src/test/java/cn/hutool/json/Issue3790Test.java
									
									
									
									
									
										Normal 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; | ||||
| 	} | ||||
| } | ||||
| @@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil; | ||||
| import cn.hutool.core.exceptions.DependencyException; | ||||
| import cn.hutool.core.io.IORuntimeException; | ||||
| import cn.hutool.core.util.CharUtil; | ||||
| import cn.hutool.core.util.NumberUtil; | ||||
| import cn.hutool.core.util.StrUtil; | ||||
| import cn.hutool.poi.excel.ExcelDateUtil; | ||||
| import cn.hutool.poi.excel.sax.handler.RowHandler; | ||||
| @@ -264,7 +265,15 @@ public class ExcelSaxUtil { | ||||
| 		if (StrUtil.isBlank(value)) { | ||||
| 			return null; | ||||
| 		} | ||||
| 		return getNumberValue(Double.parseDouble(value), numFmtString); | ||||
|  | ||||
| 		// issue#IB0EJ9 可能精度丢失 | ||||
| 		final double number = Double.parseDouble(value); | ||||
| 		if(false == value.equals(Double.toString(number))){ | ||||
| 			// 精度丢失 | ||||
| 			return NumberUtil.toBigDecimal(value); | ||||
| 		} | ||||
|  | ||||
| 		return getNumberValue(number, numFmtString); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
|   | ||||
| @@ -9,7 +9,7 @@ public class IssueIB0EJ9Test { | ||||
| 	@Test | ||||
| 	@Disabled | ||||
| 	void saxReadTest() { | ||||
| 		ExcelUtil.readBySax(FileUtil.file("d:/test/bbb.xlsx"), "Sheet1", | ||||
| 		ExcelUtil.readBySax(FileUtil.file("d:/test/数值型测试.xlsx"), "hcm工资表", | ||||
| 			(sheetIndex, rowIndex, rowlist) -> Console.log("[{}] [{}] {}", sheetIndex, rowIndex, rowlist)); | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Looly
					Looly