前臺輸入手機號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。
由於之前遇到問題,特此註明