读书人

关于jxl写小数的有关问题

发布时间: 2012-05-05 17:21:10 作者: rapoo

关于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();
[解决办法]
数据格式自定义。。。

读书人网 >Java Web开发

热点推荐