首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

关于jxl写小数的有关问题

2012-05-05 
关于jxl写小数的问题我需要用jxl来写execle文件,相应的语句为:numb new Number(6, 1, tempPrice)sheet.

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

热点排行