We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
建议先去看文档 快速开始 、常见问题 触发场景描述 用@numberformat注解转换double类型 触发Bug的代码
//表格映射对象double属性 /** * 格式化百分比 */ @NumberFormat("#.##%") @ExcelProperty("百分比") private Double num; //读取excel的Listener @Override public void invoke(DemoData demoData, AnalysisContext analysisContext) { int row = analysisContext.readRowHolder().getRowIndex(); int sheetNo = analysisContext.readSheetHolder().getSheetNo(); String sheetName = analysisContext.readSheetHolder().getSheetName(); log.info("读取到[{}]的第{}行记录:{}", sheetName, row, JSONObject.toJSONString(demoData)); }
提示的异常或者没有达到的效果
11:37:01.360 [main] INFO com.spring.component.easyexcel.listener.DemoDataListener - 读取到[Demo]的第9行记录:{"date":1589202943000,"no":"WEEK_3","num":0.6520999999999999,"zan":"点赞8"} 11:37:01.361 [main] INFO com.spring.component.easyexcel.listener.DemoDataListener - 读取到[Demo]的第10行记录:{"date":1589202943000,"no":"WEEK_4","num":0.74,"zan":"点赞9"}
建议 com.alibaba.excel.util.NumberUtils#parse 方法返回Number为BigDecimal对象,避免double、float等类型出现精度丢失的情况。 decimalFormat.setParseBigDecimal(true);
The text was updated successfully, but these errors were encountered:
修复@NumberFormat注解转换double时可能会丢失精度 #1306
@NumberFormat
cf40b87
非常感谢您的意见,已经在最新版修复。
Sorry, something went wrong.
使用最版本 easyexcel 3.3.2 ,导出字段类型为 BigDecimal ,并使用 @numberformat("#.##%")格式化 导出, 当字段值为 0.0 时 会被format成 .% ; 这个问题应该没有被修复
你还没理解 format 用法 在注解中,需要指定数字的格式化规则,规则为字符串类型的参数。该参数应使用 # 和 0 两个字符来表示数字的占位符。
具体格式化规则可以参考 Java 中的 DecimalFormat 类。
目前对 @numberformat("#,###.##") 中 ,如果是整数,还存在点的问题,请问有修复吗
zhuangjiaju
No branches or pull requests
建议先去看文档
快速开始 、常见问题
触发场景描述
用@numberformat注解转换double类型
触发Bug的代码
提示的异常或者没有达到的效果
11:37:01.360 [main] INFO com.spring.component.easyexcel.listener.DemoDataListener - 读取到[Demo]的第9行记录:{"date":1589202943000,"no":"WEEK_3","num":0.6520999999999999,"zan":"点赞8"}
11:37:01.361 [main] INFO com.spring.component.easyexcel.listener.DemoDataListener - 读取到[Demo]的第10行记录:{"date":1589202943000,"no":"WEEK_4","num":0.74,"zan":"点赞9"}
建议
com.alibaba.excel.util.NumberUtils#parse 方法返回Number为BigDecimal对象,避免double、float等类型出现精度丢失的情况。 decimalFormat.setParseBigDecimal(true);
The text was updated successfully, but these errors were encountered: