Bug 53076 - cell.getNumericCellValue() returns incorrect results sometimes
Summary: cell.getNumericCellValue() returns incorrect results sometimes
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.6-FINAL
Hardware: PC All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-13 14:06 UTC by rohit.vats
Modified: 2012-04-15 02:42 UTC (History)
1 user (show)



Attachments
File demonstrating the bug (26.50 KB, application/vnd.ms-excel)
2012-04-13 14:06 UTC, rohit.vats
Details

Note You need to log in before you can comment on or make changes to this bug.
Description rohit.vats 2012-04-13 14:06:27 UTC
Created attachment 28604 [details]
File demonstrating the bug

In an excel sheet processed through poi, getNumericCellValue() returned an incorrect result for a decimal value. The file is attached. The issue happens with the "Quantity" field of the first second row (-23,530.9150).

Value in .xls file: -23,530.9150
Formatting: Category - Number, Decimal Places - 4, Use 1000 separator - True
Value returned by getNumericCellValue: -23530.915000000045
Comment 1 Nick Burch 2012-04-13 14:12:18 UTC
getNumericCellValue() returns the number stored in the file, which is a floating point. If you want a string that looks the same as excel shows, use something like DataFormatter to format your number
Comment 2 rohit.vats 2012-04-13 15:27:00 UTC
Ok, the actual value in the field seems to be -23530.915, which is why I wondered why getNumericCellValue() returned -23530.915000000045.

Any thoughts?
Comment 3 rohit.vats 2012-04-13 15:28:43 UTC
(In reply to comment #1)
> getNumericCellValue() returns the number stored in the file, which is a
> floating point. If you want a string that looks the same as excel shows, use
> something like DataFormatter to format your number

Ok, the actual value in the field seems to be -23530.915, which is why I
wondered why getNumericCellValue() returned -23530.915000000045.

Any thoughts?
Comment 4 Nick Burch 2012-04-13 15:53:46 UTC
http://en.wikipedia.org/wiki/Floating_point
Comment 5 Richard Ngo 2012-04-15 02:42:15 UTC
have you tried using http://poi.apache.org/apidocs/org/apache/poi/ss/util/NumberToTextConverter.html?