summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-03-21 22:46:26 +0500
committerAndras Timar <andras.timar@collabora.com>2024-03-27 14:33:18 +0100
commit91c2b51a7c728d8f287eba2927216689f07c29f0 (patch)
tree6226048057db46dae344b282e130ff0202814481 /svl
parentade399fa2f96c76843e676bc3664357b02893f89 (diff)
tdf#160306: make sure that SvNumberFormatter agrees with ROUND output
After commit 9eb9083ff2fdaeb96399a0830a4394de4e29ef64 (Use Dragonbox to implement doubleTo*String*, 2022-02-18), the rounding that is used in SvNumberFormatter became strictly more correct; however, it now differed from what ROUND spreadsheet function returned, because the latter uses rtl_math_round, which calls rtl::math::approxFloor. To make the visual number representation consistent, this change uses rtl_math_round in SvNumberformat::ImpGetNumberOutput. Change-Id: I05b0bed7d3a6c73584a77adbae2835c95be249fa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165142 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> (cherry picked from commit 805dd6bee49164d9a77de4ea9e0d53b416daca7a) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165124 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svl')
-rw-r--r--svl/qa/unit/svl.cxx20
-rw-r--r--svl/source/numbers/zformat.cxx2
2 files changed, 22 insertions, 0 deletions
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index 4fa56f4bccd4..969dfa166bae 100644
--- a/svl/qa/unit/svl.cxx
+++ b/svl/qa/unit/svl.cxx
@@ -1993,6 +1993,26 @@ CPPUNIT_TEST_FIXTURE(Test, testLanguageNone)
CPPUNIT_ASSERT_EQUAL(OUString("dd.mm.yyyy"), pFormat->GetMappedFormatstring(keywords, ldw));
}
+CPPUNIT_TEST_FIXTURE(Test, testTdf160306)
+{
+ // Check some cases, where the output of ROUND and of number formatter differed
+ SvNumberFormatter aFormatter(m_xContext, LANGUAGE_ENGLISH_US);
+ sal_uInt32 format = aFormatter.GetEntryKey(u"0.00", LANGUAGE_ENGLISH_US);
+ CPPUNIT_ASSERT(format != NUMBERFORMAT_ENTRY_NOT_FOUND);
+ OUString output;
+ const Color* color;
+ aFormatter.GetOutputString(2697.0649999999996, format, output, &color);
+ // Without the fix in place, this would fail with
+ // - Expected: 2697.07
+ // - Actual : 2697.06
+ CPPUNIT_ASSERT_EQUAL(u"2697.07"_ustr, output);
+ aFormatter.GetOutputString(57.374999999999993, format, output, &color);
+ // Without the fix in place, this would fail with
+ // - Expected: 57.38
+ // - Actual : 57.37
+ CPPUNIT_ASSERT_EQUAL(u"57.38"_ustr, output);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index b5c8757ef2e6..313a59827947 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -4407,6 +4407,8 @@ bool SvNumberformat::ImpGetNumberOutput(double fNumber,
{
nPrecExp = 0;
}
+ // Make sure that Calc's ROUND and formatted output agree
+ fNumber = rtl_math_round(fNumber, rInfo.nCntPost, rtl_math_RoundingMode_Corrected);
if (rInfo.nCntPost) // Decimal places
{
if ((rInfo.nCntPost + nPrecExp) > 15 && nPrecExp < 15)