Bug 66501 - Incorrect calculation because of using 'double' data type
Summary: Incorrect calculation because of using 'double' data type
Status: RESOLVED WONTFIX
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 5.2.1-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-03-01 18:47 UTC by Mykhailo Myronenko
Modified: 2023-03-01 19:00 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mykhailo Myronenko 2023-03-01 18:47:12 UTC
Since POI uses 'double' datatype to perform calculations the sum of the following arguments (5.6, 5.8) will be 11.399999999999999.

Here is the explanation why we get such result when we sum up those arguments: https://stackoverflow.com/a/322875.

Consider using BigDecimal instead of 'double'.
Comment 1 PJ Fanning 2023-03-01 19:00:53 UTC
Excel uses doubles under the hood. POI is an attempt to approximate what Excel does. If you want exact results instead of floating point approximations, please do not use Excel or POI.

What Excel does is use formats to define how the approximate values should be displayed. It's hard to imagine how they came up with this but this is what we are stuck with. Use POI's DataFormatter to apply the cell formats.

Closing this issue as: Won't Fix