Hello MSB,

You post is very helpful, and my problem is gone, thank you a million!

Yhqian99



MSB wrote:
> 
> In Excel, there is a difference between what a cell contains and how that
> data is presented to the user - think of a date as a good example; a
> numeric value that can be formatted to appear in different ways.
> 
> So, bearing that in mind, you need to create an apply a style to the cell
> (HSSFCellStyle). Most importantly, you need to associate a data format
> (HSSFDataFormat) with the cell style that will ensure the value is
> displayed exactly as you want.
> 
> Take a look at this piece of code;
> 
>  http://poi.apache.org/spreadsheet/quick-guide.html#DataFormats
> http://poi.apache.org/spreadsheet/quick-guide.html#DataFormats 
> 
> Not all of it applies to your example, the bit that does is here;
> 
> row = sheet.createRow(rowNum++);
> cell = row.createCell(colNum);
> cell.setCellValue(11111.25);
> style = wb.createCellStyle();
> style.setDataFormat(format.getFormat("#,##0.0000"));
> cell.setCellStyle(style);
> 
> The line you want to look at most closely is this one;
> 
> style.setDataFormat(format.getFormat("#,##0.0000"));
> 
> as it contains the formatting string. If you change that String to
> "#,##0.00" then it will display just two digits after the decimal point.
> 
> 
> 
> yhqian99 wrote:
>> 
>> Hello all,
>> 
>> I am setting a float number like 34.44 to a numerical cell, but when I
>> open the .xls file by Microsoft Excel, it show as 34.4399986267089, it
>> looks like the HSSFCell's setCellValue(double value) automatically
>> convert a float to a double.  But I don't want the extra digits, how can
>> I make the .xls file shows 34.44 instead of 34.4399986267089
>> 
>>  Thanks,
>> 
>> Yhqian99
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/a-float-number-set-to-a-numeric-cell-is-changed-to-a-double-tp22302151p22306896.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@poi.apache.org
For additional commands, e-mail: user-h...@poi.apache.org

Reply via email to