天天看点

java, poi 取消科学计数法

前台输入手机号13777777777,如果是为Double类型接收,就会自动转为科学计数法,非常讨厌,这是我们经常遇到的

找了下,一般是Double转String,方法一般有两种:

1.利用String.format()

saleUnilateImport.setPhone(String.format("%.4f", row.getCell(1).getNumericCellValue()));//15145117218.0000保留4位小数

String.format("%.0f", row.getCell(0).getNumericCellValue())//15145117218,取整!

2.利用DecimalFormat类

DecimalFormat df = new DecimalFormat("#");//转换成整型

saleUnilateImport.setPhone(df.format(row.getCell(1).getNumericCellValue()));

3.利用DecimalFormat类

DecimalFormat df = new DecimalFormat("#,##0.00");//保留两位小数且不用科学计数法saleUnilateImport.setPhone(df.format(row.getCell(1).getNumericCellValue()));

注: 本文转自ITEYE。 

由于之前遇到问题,特此注明