https://bz.apache.org/bugzilla/show_bug.cgi?id=62506

            Bug ID: 62506
           Summary: Wrong implementation of truncation
           Product: POI
           Version: 3.14-FINAL
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: SS Common
          Assignee: dev@poi.apache.org
          Reporter: c.dellac...@bravosolution.com
  Target Milestone: ---

Created attachment 35998
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=35998&action=edit
Example to reproduce the problem and patch (maven)

We have a column with a formula which must truncate to 2 figures its result;
the problem is that some values are truncated in a wrong way.
For example 0.29 is truncated to 0.28, 1.15 is truncated to 1.14 and so on. 

The reason of the error is due to Java binary representation of a Double.
To fix it we have used BigDecimal class.
Moreover now the behavior is different from MS Excel because the number of
figures to truncate is not managed as an integer value. Also MS Excel accepts
this number as double value but it manages the value as an integer. 

Attached there is a simple code example and a patch with our correction.

We have fixed the function TRUNC in the class NumericFunction, but the error is
more generic and is also present in the simplest numerical calculations (for
example 0.1 + 0.2 does not result in 0.3).

Executing the attached example we have as result:

0.1 + 0.2 = 0.30000000000000004  
0.28       -> TRUNC(number,2) ->               0.28      
0.29       -> TRUNC(number,2) ->               0.28

The same problem is present also in 3.17.

Thanks

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org
For additional commands, e-mail: dev-h...@poi.apache.org

Reply via email to