]> granicus.if.org Git - icu/commitdiff
ICU-13700 Adding DecimalFormat "scale" getter/setter and implementation in the new...
authorShane Carr <shane@unicode.org>
Sat, 14 Apr 2018 09:49:12 +0000 (09:49 +0000)
committerShane Carr <shane@unicode.org>
Sat, 14 Apr 2018 09:49:12 +0000 (09:49 +0000)
X-SVN-Rev: 41232

icu4c/source/i18n/decimfmt.cpp
icu4c/source/i18n/number_decimfmtprops.cpp
icu4c/source/i18n/number_decimfmtprops.h
icu4c/source/i18n/unicode/decimfmt.h

index 8ca75eb10a9dee9dae5ec844b3c5398828ebec0b..f95b8112310d5bcf199a63a13ca357e84178d054 100644 (file)
@@ -166,6 +166,10 @@ DecimalFormat::setAttribute(UNumberFormatAttribute attr, int32_t newValue, UErro
             setMultiplier(newValue);
             break;
 
+        case UNUM_SCALE:
+            setScale(newValue);
+            break;
+
         case UNUM_GROUPING_SIZE:
             setGroupingSize(newValue);
             break;
@@ -221,7 +225,6 @@ DecimalFormat::setAttribute(UNumberFormatAttribute attr, int32_t newValue, UErro
             status = U_UNSUPPORTED_ERROR;
             break;
     }
-    // TODO: UNUM_SCALE?
     // TODO: UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS?
     return *this;
 }
@@ -273,6 +276,9 @@ int32_t DecimalFormat::getAttribute(UNumberFormatAttribute attr, UErrorCode& sta
         case UNUM_MULTIPLIER:
             return getMultiplier();
 
+        case UNUM_SCALE:
+            return getScale();
+
         case UNUM_GROUPING_SIZE:
             return getGroupingSize();
 
@@ -311,7 +317,6 @@ int32_t DecimalFormat::getAttribute(UNumberFormatAttribute attr, UErrorCode& sta
             break;
     }
     // TODO: UNUM_FORMAT_FAIL_IF_MORE_THAN_MAX_DIGITS?
-    // TODO: UNUM_SCALE?
 
     return -1; /* undefined */
 }
@@ -657,6 +662,15 @@ void DecimalFormat::setMultiplier(int32_t multiplier) {
     refreshFormatterNoError();
 }
 
+int32_t DecimalFormat::getScale() const {
+    return fProperties->scaleMultiplier;
+}
+
+void DecimalFormat::setScale(int32_t newValue) {
+    fProperties->scaleMultiplier = newValue;
+    refreshFormatterNoError();
+}
+
 double DecimalFormat::getRoundingIncrement(void) const {
     return fExportedProperties->roundingIncrement;
 }
index f7d486d699e43a3e1ae6a1bf21b6cee14bd4bdec..412a04d8f35af506835e055b4b2a2b6d6d41a51a 100644 (file)
@@ -54,6 +54,7 @@ void DecimalFormatProperties::clear() {
     positiveSuffixPattern.setToBogus();
     roundingIncrement = 0.0;
     roundingMode.nullify();
+    scaleMultiplier = 0;
     secondaryGroupingSize = -1;
     signAlwaysShown = false;
 }
@@ -98,6 +99,7 @@ bool DecimalFormatProperties::operator==(const DecimalFormatProperties &other) c
     eq = eq && positiveSuffixPattern == other.positiveSuffixPattern;
     eq = eq && roundingIncrement == other.roundingIncrement;
     eq = eq && roundingMode == other.roundingMode;
+    eq = eq && scaleMultiplier == other.scaleMultiplier;
     eq = eq && secondaryGroupingSize == other.secondaryGroupingSize;
     eq = eq && signAlwaysShown == other.signAlwaysShown;
     return eq;
index 4ad3225ba39c8c75824b64dddc24fb6c5e3b4c71..2cac011c7d6f903e7a0a274a0d0a887b6d2fbb43 100644 (file)
@@ -128,6 +128,7 @@ struct U_I18N_API DecimalFormatProperties {
     UnicodeString positiveSuffixPattern;
     double roundingIncrement;
     NullableValue<RoundingMode> roundingMode;
+    int32_t scaleMultiplier;
     int32_t secondaryGroupingSize;
     bool signAlwaysShown;
 
index ee6db91d1c589f8b5bdf1a377293d7a54b4fe620..1ce1ea93981e6a840d787fef41c18e225aa54bd2 100644 (file)
@@ -1320,6 +1320,7 @@ class U_I18N_API DecimalFormat : public NumberFormat {
      * For a percentage, set the suffixes to have "%" and the multiplier to be 100.
      * (For Arabic, use arabic percent symbol).
      * For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000.
+     * It is possible to set both via setMultiplier() as via setScale() simultaneously.
      *
      * @param newValue    the new value of the multiplier for use in percent, permill, etc.
      * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
@@ -1327,6 +1328,27 @@ class U_I18N_API DecimalFormat : public NumberFormat {
      */
     virtual void setMultiplier(int32_t newValue);
 
+    /**
+     * Gets a multiplier for the given power of ten.
+     * For example, scale of 2 corresponds to a multiplier of 100.
+     *
+     * @return    the multiplier for use in percent, permill, etc.
+     * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
+     * @draft ICU 62
+     */
+    int32_t getScale(void) const;
+
+    /**
+     * Sets a multiplier for the given power of ten.
+     * For example, scale of 2 corresponds to a multiplier of 100.
+     * It is possible to set both via setMultiplier() as via setScale() simultaneously.
+     *
+     * @param newValue    the new value of the multiplier for use in percent, permill, etc.
+     * Examples: with 100, 1.23 -> "123", and "123" -> 1.23
+     * @draft ICU 62
+     */
+    virtual void setScale(int32_t newValue);
+
     /**
      * Get the rounding increment.
      * @return A positive rounding increment, or 0.0 if a custom rounding