读取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();