读取EXCEL单元格,小数问题

    当读取Excel中的小数时,通过Cell c = sheet.getCell(j, i);

     String content = c.getContext().trim();获取的小数存在不准确的情况,

比如:245.205 获到的结果==245.20;而我想要的结果是四舍五入的效果。

这时可通过转换

     http://yuanliyin.iteye.com/blog/656251

     NumberCell numberCell = (NumberCell)rSheet.getCell(j, i);

     double namberValue = numberCell.getValue();

     获取精确的值。在进行四舍五入。

    通常我会用new DecimalFormat("#.00"),可发现245.205 转换的结果==245.20;

可通过

public static Double round(Double doubleValue, int scale){ 
      String text=doubleValue.toString();
      BigDecimal bd=new BigDecimal(text)
                       .setScale(scale,BigDecimal.ROUND_HALF_UP); 
      Double result=bd.doubleValue(); 
      return result; 
} 

 转换;http://blog.csdn.net/weboffice/article/details/4937992

猜你喜欢

转载自llmy.iteye.com/blog/1457853