java中poi在读取excel时,数字自动带“.0”处理方法
下文讲述今天项目中遇到的问题,如下所示:
我使用poi读取excel,发现数字都自动带.0 如: cell_1.getNumericCellValue() 输出的数字都带.0 那么如何使这些数字不带".0"呢?下文讲一一道来,如下所示:
//方法1
double d = cell_1.getNumericCellValue();
NumberFormat nf = NumberFormat.getInstance();
String s = nf.format(d);
if (s.indexOf(",") >= 0) {
s = s.replace(",", "");
}
map.put("hotelId", s);
//方法2
double d = cell_1.getNumericCellValue();
//将double类型转换为对应的字段类型
map.put("id", Double.valueOf(d).longValue()+"");
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


