天天看點

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。 

由于之前遇到問題,特此注明