summaryrefslogtreecommitdiff
path: root/svl/qa/unit
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-03-21 22:46:26 +0500
committerMike Kaganski <mike.kaganski@collabora.com>2024-03-22 04:00:45 +0100
commit805dd6bee49164d9a77de4ea9e0d53b416daca7a (patch)
tree9b8ed0e8af1795dbf6ded95dbc86edf72bef2846 /svl/qa/unit
parent71efd6046488b952f679936ea1c4a415f4989b18 (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>
Diffstat (limited to 'svl/qa/unit')
-rw-r--r--svl/qa/unit/svl.cxx20
1 files changed, 20 insertions, 0 deletions
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index d24729bc7f43..118016de3b68 100644
--- a/svl/qa/unit/svl.cxx
+++ b/svl/qa/unit/svl.cxx
@@ -1995,6 +1995,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);
}