]> granicus.if.org Git - icu/commitdiff
ICU-21693 Fix FormattedNumber::toDecimalNumber on 0
authorShane F. Carr <shane@unicode.org>
Sat, 21 Aug 2021 03:30:31 +0000 (22:30 -0500)
committerShane F. Carr <shane@unicode.org>
Tue, 24 Aug 2021 02:10:07 +0000 (21:10 -0500)
icu4c/source/i18n/number_decimalquantity.cpp
icu4c/source/test/intltest/numbertest_api.cpp

index 5203b73c0bdfa1e1ce873339e567b40c618fd0f8..441d168290812c2dab5f9f4c92b61b70fe18e03c 100644 (file)
@@ -639,6 +639,7 @@ DecNum& DecimalQuantity::toDecNum(DecNum& output, UErrorCode& status) const {
     // Special handling for zero
     if (precision == 0) {
         output.setTo("0", status);
+        return output;
     }
 
     // Use the BCD constructor. We need to do a little bit of work to convert, though.
index a42b4d504a44a9fbb3f908fc73b4dc0a803fbc46..b0aa5b45284494850aa43e47da314437343d8f00 100644 (file)
@@ -5378,6 +5378,12 @@ void NumberFormatterApiTest::toDecimalNumber() {
         u"৯৮,৭৬,৫০,০০,০০,০০,০০০", fn.toString(status));
     assertEquals(u"Should have expected toDecimalNumber string result",
         "9.8765E+14", fn.toDecimalNumber<std::string>(status).c_str());
+
+    fn = NumberFormatter::withLocale("bn-BD").formatDouble(0, status);
+    assertEquals("Should have expected localized string result",
+        u"০", fn.toString(status));
+    assertEquals(u"Should have expected toDecimalNumber string result",
+        "0", fn.toDecimalNumber<std::string>(status).c_str());
 }
 
 void NumberFormatterApiTest::microPropsInternals() {