Bug 134763 - Writer round behavior differs from Word in a table formula
Summary: Writer round behavior differs from Word in a table formula
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Writer-Tables-Formulas
  Show dependency treegraph
 
Reported: 2020-07-12 20:43 UTC by Michael Warner
Modified: 2020-11-14 09:21 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
Example document (11.47 KB, application/vnd.oasis.opendocument.text)
2020-07-12 20:44 UTC, Michael Warner
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Warner 2020-07-12 20:43:54 UTC
Description:
When using the ROUND feature of a table formula in writer, the number of digits to round to, exceeds the number of decimal places in the number provided, LO Writer rounds the number up or down in the last digit anyway. MS Word does not apply rounding in this case. 

Steps to Reproduce:
1. Create a table
2. Insert formula (4.545 ROUND 5)


Actual Results:
Result is 4.55

Expected Results:
MS Word returns 4.545


Reproducible: Always


User Profile Reset: No



Additional Info:
Version: 6.0.7.3
Build ID: 1:6.0.7-0ubuntu0.18.04.2
CPU threads: 12; OS: Linux 4.15; UI render: default; VCL: gtk3; 
Locale: en-US (en_US.UTF-8); Calc: group
Comment 1 Michael Warner 2020-07-12 20:44:48 UTC
Created attachment 162941 [details]
Example document
Comment 2 himajin100000 2020-07-27 04:56:16 UTC
I haven't understood the algorithm yet(just for lazyness).

https://opengrok.libreoffice.org/xref/core/sw/source/core/bastyp/calc.cxx?r=474a9171#920
Comment 3 himajin100000 2020-07-27 05:13:34 UTC
Reproduced

probably the cause is not the calculation, but the format Table uses.
Comment 4 himajin100000 2020-07-27 05:24:01 UTC
you can find "Number Format" toolbar-item, not "Number Format(Decimal), if you enable Table toolbar displayed around a status bar. Clicking this toolbar-item shows a dialog to specify Numberformat
Comment 5 sora34ce 2020-09-07 16:12:15 UTC
(In reply to himajin100000 from comment #4)
> you can find "Number Format" toolbar-item, not "Number Format(Decimal), if
> you enable Table toolbar displayed around a status bar. Clicking this
> toolbar-item shows a dialog to specify Numberformat

I definitely did test this; specifying number format means I could potentially get 4.545 instead of 4.55. The default hasn't been fixed whatsoever in later updates.

Version: 7.1.0.0.alpha0+
Build ID: 52820b52b3bca45e2db527d1cc5f4488b2e0b9d0
CPU threads: 8; OS: Mac OS X 10.15.6; UI render: default; VCL: osx
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded
Comment 6 Mike Kaganski 2020-11-14 09:21:59 UTC
This is not a bug. As mentioned in comment 3, the visible result in not related to rounding, but to formatting - which are different concepts.

Cell D4 in the table has a "Insert Formula" field with the formula "(4.545 ROUND 5)". Its result is indeed 4.545. Then the field also has *format* - which is "Standard". That format shows up to two decimal digits for a number. So the *displayed result* is rightfully 4.55.

But the number contained in the cell is still the correct one - 4.545. You can check that using a new row in the table, and putting this formula (not a field!) to D6: "=<D4>+1". Then if you use Table->Number Format to increase decimal places, you would see that the result is 5.545, which proves that D4 has the correct numeric value.

Then you could change the field's formula in D4 to "(4.545 ROUND 2)", and see that D6 now shows 5.55 (although D4 is visually unchanged). That is because the ROUND changes the value, while formatting only changes display - that a very important thing about formatting.

And then you may change the format used in the D4's field, clicking on "Additional formats..." element in the "Format" list of the field editor dialog. Put there any number into the decimal places box.

Closing NOTABUG.