防止java读入double自动补.0和自动读成科学计数法
private static String customExcelNumericFormat(double d) {
NumberFormat nf = NumberFormat.getNumberInstance();
String temp = d + "";
// 科学计数法中的n(10的n次方)
int n = 0;
// 判断有多少位有效小数
int a = 0;
// 如果该数字使用了科学计数法
if (temp.indexOf("E") >= 0) {
// 判断出要移多少位
String auxiliaryStr = temp.split("E")[1];
String realStr = temp.split("E")[0];
n = Integer.parseInt(auxiliaryStr);
// 有多少位有效小数(科学计数法)
a = (realStr).length() - (realStr).indexOf(".") - 1 - n;
} else {
// 有多少位有效小数(非科学计数法)
a = (d + "").length() - (d + "").indexOf(".") - 1;
}
if (a == 1 && (d + "").endsWith(".0")) {
// 如果excel里本无小数是java读取时自动加的.0那就直接将小数位数设0
nf.setMinimumFractionDigits(0);
} else {
// 有小数的按小数位数设置
nf.setMinimumFractionDigits(a);
}
String s = nf.format(d);
if (s.indexOf(",") >= 0) {
s = s.replace(",", "");
}
return s;
}