显示精度问题-double的科学计数法和bigdicemal的精度丢失问题

读取excel的数据

下面是读取excel的数字问题
1,如果采用DecimalFormat(“0.00”);控制,导致的问题很明显,所有的数据都是两位数的精度
2,String.valueOf(cell.getNumericCellValue());直接采用了double的数据,16位会出现科学技术法
3,BigDecimal(cell.getNumericCellValue());采用double,double精度会丢失
4,BigDecimal(Double.toString(cell.getNumericCellValue()));出现了科学技术法

                        DecimalFormat df = new DecimalFormat("0.00");
                        cellValue = df.format(cell.getNumericCellValue());
                        BigDecimal bigDecimal = new BigDecimal(Double.toString(cell.getNumericCellValue()));
                        cellValue = bigDecimal.toString();
//                        cellValue = String.valueOf(cell.getNumericCellValue());//string是科学技术法问题

解决办法
1,为了去掉后面的小数位显示不必要的0,需要stripTrailingZeros
2,为了防止科学技术法,需要输出特定的字符串类型

                        BigDecimal bigDecimal = new BigDecimal(Double.toString(cell.getNumericCellValue()));
                        cellValue = bigDecimal.stripTrailingZeros().toPlainString();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值