Bug 66498

Summary: Other: strange behaviour of round down function
Product: LibreOffice Reporter: novell191
Component: CalcAssignee: Not Assigned <libreoffice-bugs>
Status: RESOLVED NOTABUG    
Severity: normal CC: miguelangelrv
Priority: medium    
Version: 4.0.4.2 release   
Hardware: Other   
OS: Linux (All)   
Whiteboard: BSA
Crash report or crash signature: Regression By:
Attachments: just an example to clarify

Description novell191 2013-07-02 10:29:45 UTC
Created attachment 81865 [details]
just an example to clarify

Problem description: 
i'm not sure about name function, i use different language.
When i round down the difference of 2 number and the weight for rounding has opposite sign of the number to round i get error 502

trying to avoid this problem i find another one.
If i try to round down at 2nd decimal witch has no need to be rounded i get error
for example:
right way              0,02 -> 0,02
round down function    0,02 -> 0,01

              
Operating System: Ubuntu
Version: 4.0.4.2 release
Comment 1 m_a_riosv 2013-07-03 00:35:55 UTC
Please take a look to this bug:
https://bugs.freedesktop.org/show_bug.cgi?id=37923

Try formatting the subtracted numbers with 15 decimal places to see there is no decimals beyond the second one.
Comment 2 novell191 2013-07-04 08:46:27 UTC
i checked, the difference wasn't -0,02, but -0,019999999999996, so the round function work properly

the new question is why the difference give that "strange" number?
100 - 100,02 = -0,02 not -0,01999...
Comment 3 m_a_riosv 2013-07-04 23:58:56 UTC
I think you can find an accurate explanation here:
http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
Comment 4 novell191 2013-07-05 09:16:45 UTC
understood, i will found a workaround, thanks
Comment 5 m_a_riosv 2013-07-06 12:15:51 UTC
Hi novell191, thanks for your collaboration.

Maybe a formula like this can help in your situation:

=ROUNDDOWN(ROUND(100-100,2;3);2)

Making first a simple ROUND() with a decimal plus than in the ROUNDDOWN().

Changed the status to resolved notabug. Please if you are not agree reopen it.
Comment 6 novell191 2013-07-06 13:05:51 UTC
this work properly!
Thanks!