美文网首页
关于java读取Excel读出的数据避免科学计数法

关于java读取Excel读出的数据避免科学计数法

作者: demil | 来源:发表于2016-03-30 17:48 被阅读1459次
  • 判断读出来是否为数值型,如果是,则进行格式化
if(row.getCell(j).getCellType() == Cell.CELL_TYPE_NUMERIC)
{
    DecimalFormat df = new DecimalFormat("0");
    value = df.format(row.getCell(j).getNumericCellValue()); 
     value = subZeroAndDot(value);
}


/** * 使用正则表达式去掉多余的.与 
 *  * @param s 
    * @return 
    */
private String subZeroAndDot(String s) {
    if (s.indexOf(".0") > 0) {
        // 去掉多余的 
        s = s.replaceAll("0+?$", ""); 
       // 如果最后一位是.则去掉
        s = s.replaceAll("[.]$", "");
    } 
   return s;
}

相关文章

网友评论

      本文标题:关于java读取Excel读出的数据避免科学计数法

      本文链接:https://www.haomeiwen.com/subject/pccelttx.html