当前位置: 代码迷 >> Java Web开发 >> 关于jxl写小数的有关问题
  详细解决方案

关于jxl写小数的有关问题

热度:4010   发布时间:2013-02-25 21:21:22.0
关于jxl写小数的问题
我需要用jxl来写execle文件,相应的语句为: 
numb = new Number(6, 1, tempPrice);
 sheet.addCell(numb);

其中tempPrice是从数据库中取到的,数据库中的值为2.30。

当写完excel文件后,发现该值在excel文件中变成了2.29999995231628,请问我该如何限定格式啊,让写入的值为2.30呢

多谢了!


------解决方案--------------------------------------------------------
Java code
HSSFWorkbook wb = new HSSFWorkbook();    HSSFSheet sheet = wb.createSheet("format sheet");    HSSFCellStyle style;    HSSFDataFormat format = wb.createDataFormat();    HSSFRow row;    HSSFCell cell;    short rowNum = 0;    short colNum = 0;    row = sheet.createRow(rowNum++);    cell = row.createCell(colNum);    cell.setCellValue(11111.25);    style = wb.createCellStyle();    style.setDataFormat(format.getFormat("0.0"));    cell.setCellStyle(style);    row = sheet.createRow(rowNum++);    cell = row.createCell(colNum);    cell.setCellValue(11111.25);    style = wb.createCellStyle();    style.setDataFormat(format.getFormat("#,##0.0000"));    cell.setCellStyle(style);    FileOutputStream fileOut = new FileOutputStream("workbook.xls");    wb.write(fileOut);    fileOut.close();
------解决方案--------------------------------------------------------
数据格式自定义。。。
  相关解决方案