ICU-13700 Adding DecimalFormat "scale" getter/setter and implementation in the new number formatting pipeline.

X-SVN-Rev: 41232
This commit is contained in:
Shane Carr 2018-04-14 09:49:12 +00:00
parent ce846b6b34
commit 02c492db8a
4 changed files with 41 additions and 2 deletions

View 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;
}

View 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;

View 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;

View 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