mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-13700 Renaming new getter/setter to magnitudeScale.
X-SVN-Rev: 41246
This commit is contained in:
parent
55080e2804
commit
1aa5185a36
9 changed files with 50 additions and 24 deletions
|
@ -167,7 +167,7 @@ DecimalFormat::setAttribute(UNumberFormatAttribute attr, int32_t newValue, UErro
|
|||
break;
|
||||
|
||||
case UNUM_SCALE:
|
||||
setScale(newValue);
|
||||
setMultiplierScale(newValue);
|
||||
break;
|
||||
|
||||
case UNUM_GROUPING_SIZE:
|
||||
|
@ -280,7 +280,7 @@ int32_t DecimalFormat::getAttribute(UNumberFormatAttribute attr, UErrorCode& sta
|
|||
return getMultiplier();
|
||||
|
||||
case UNUM_SCALE:
|
||||
return getScale();
|
||||
return getMultiplierScale();
|
||||
|
||||
case UNUM_GROUPING_SIZE:
|
||||
return getGroupingSize();
|
||||
|
@ -667,12 +667,12 @@ void DecimalFormat::setMultiplier(int32_t multiplier) {
|
|||
refreshFormatterNoError();
|
||||
}
|
||||
|
||||
int32_t DecimalFormat::getScale() const {
|
||||
return fProperties->scaleMultiplier;
|
||||
int32_t DecimalFormat::getMultiplierScale() const {
|
||||
return fProperties->multiplierScale;
|
||||
}
|
||||
|
||||
void DecimalFormat::setScale(int32_t newValue) {
|
||||
fProperties->scaleMultiplier = newValue;
|
||||
void DecimalFormat::setMultiplierScale(int32_t newValue) {
|
||||
fProperties->multiplierScale = newValue;
|
||||
refreshFormatterNoError();
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ void DecimalFormatProperties::clear() {
|
|||
minimumIntegerDigits = -1;
|
||||
minimumSignificantDigits = -1;
|
||||
multiplier = 1;
|
||||
multiplierScale = 0;
|
||||
negativePrefix.setToBogus();
|
||||
negativePrefixPattern.setToBogus();
|
||||
negativeSuffix.setToBogus();
|
||||
|
@ -55,7 +56,6 @@ void DecimalFormatProperties::clear() {
|
|||
positiveSuffixPattern.setToBogus();
|
||||
roundingIncrement = 0.0;
|
||||
roundingMode.nullify();
|
||||
scaleMultiplier = 0;
|
||||
secondaryGroupingSize = -1;
|
||||
signAlwaysShown = false;
|
||||
}
|
||||
|
@ -83,6 +83,7 @@ bool DecimalFormatProperties::operator==(const DecimalFormatProperties &other) c
|
|||
eq = eq && minimumIntegerDigits == other.minimumIntegerDigits;
|
||||
eq = eq && minimumSignificantDigits == other.minimumSignificantDigits;
|
||||
eq = eq && multiplier == other.multiplier;
|
||||
eq = eq && multiplierScale == other.multiplierScale;
|
||||
eq = eq && negativePrefix == other.negativePrefix;
|
||||
eq = eq && negativePrefixPattern == other.negativePrefixPattern;
|
||||
eq = eq && negativeSuffix == other.negativeSuffix;
|
||||
|
@ -101,7 +102,6 @@ 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;
|
||||
|
|
|
@ -100,7 +100,7 @@ struct U_I18N_API DecimalFormatProperties {
|
|||
int32_t formatWidth;
|
||||
int32_t groupingSize;
|
||||
bool groupingUsed;
|
||||
int32_t magnitudeMultiplier;
|
||||
int32_t magnitudeMultiplier; // internal field like multiplierScale but separate to avoid conflict
|
||||
int32_t maximumFractionDigits;
|
||||
int32_t maximumIntegerDigits;
|
||||
int32_t maximumSignificantDigits;
|
||||
|
@ -110,6 +110,7 @@ struct U_I18N_API DecimalFormatProperties {
|
|||
int32_t minimumIntegerDigits;
|
||||
int32_t minimumSignificantDigits;
|
||||
int32_t multiplier;
|
||||
int32_t multiplierScale; // ICU4C-only
|
||||
UnicodeString negativePrefix;
|
||||
UnicodeString negativePrefixPattern;
|
||||
UnicodeString negativeSuffix;
|
||||
|
@ -129,7 +130,6 @@ struct U_I18N_API DecimalFormatProperties {
|
|||
UnicodeString positiveSuffixPattern;
|
||||
double roundingIncrement;
|
||||
NullableValue<RoundingMode> roundingMode;
|
||||
int32_t scaleMultiplier;
|
||||
int32_t secondaryGroupingSize;
|
||||
bool signAlwaysShown;
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class MultiplierFormatHandler : public MicroPropsGenerator, public UMemory {
|
|||
|
||||
/** Gets a Scale from a DecimalFormatProperties. In Java, defined in RoundingUtils.java */
|
||||
static inline Scale scaleFromProperties(const DecimalFormatProperties& properties) {
|
||||
int32_t magnitudeMultiplier = properties.magnitudeMultiplier + properties.scaleMultiplier;
|
||||
int32_t magnitudeMultiplier = properties.magnitudeMultiplier + properties.multiplierScale;
|
||||
int32_t arbitraryMultiplier = properties.multiplier;
|
||||
if (magnitudeMultiplier != 0 && arbitraryMultiplier != 1) {
|
||||
return Scale::byDoubleAndPowerOfTen(arbitraryMultiplier, magnitudeMultiplier);
|
||||
|
|
|
@ -1301,7 +1301,7 @@ class U_I18N_API DecimalFormat : public NumberFormat {
|
|||
* @param value The new setting for whether to show plus sign on positive numbers
|
||||
* @internal Technical Preview
|
||||
*/
|
||||
void setSignAlwaysShown(UBool value);
|
||||
virtual void setSignAlwaysShown(UBool value);
|
||||
|
||||
/**
|
||||
* Get the multiplier for use in percent, permill, etc.
|
||||
|
@ -1309,6 +1309,8 @@ class U_I18N_API DecimalFormat : public NumberFormat {
|
|||
* (For Arabic, use arabic percent symbol).
|
||||
* For a permill, set the suffixes to have "\\u2031" and the multiplier to be 1000.
|
||||
*
|
||||
* The number may also be multiplied by a power of ten; see getMultiplierScale().
|
||||
*
|
||||
* @return the multiplier for use in percent, permill, etc.
|
||||
* Examples: with 100, 1.23 -> "123", and "123" -> 1.23
|
||||
* @stable ICU 2.0
|
||||
|
@ -1320,7 +1322,9 @@ 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.
|
||||
*
|
||||
* This method only supports integer multipliers. To multiply by a non-integer, pair this
|
||||
* method with setMultiplierScale().
|
||||
*
|
||||
* @param newValue the new value of the multiplier for use in percent, permill, etc.
|
||||
* Examples: with 100, 1.23 -> "123", and "123" -> 1.23
|
||||
|
@ -1332,22 +1336,30 @@ class U_I18N_API DecimalFormat : public NumberFormat {
|
|||
* 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
|
||||
* This method is analogous to UNUM_SCALE in getAttribute.
|
||||
*
|
||||
* @return the new value of the power-of-ten multiplier.
|
||||
* @draft ICU 62
|
||||
*/
|
||||
int32_t getScale(void) const;
|
||||
int32_t getMultiplierScale(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.
|
||||
* Sets a power of ten by which number should be multiplied before formatting, which
|
||||
* can be combined with setMultiplier() to multiply by any arbitrary decimal value.
|
||||
*
|
||||
* @param newValue the new value of the multiplier for use in percent, permill, etc.
|
||||
* Examples: with 100, 1.23 -> "123", and "123" -> 1.23
|
||||
* For example, to multiply numbers by 0.5 before formatting, you can do:
|
||||
*
|
||||
* <pre>
|
||||
* df.setMultiplier(5);
|
||||
* df.setMultiplierScale(-1);
|
||||
* </pre>
|
||||
*
|
||||
* This method is analogous to UNUM_SCALE in setAttribute.
|
||||
*
|
||||
* @param newValue the new value of the power-of-ten multiplier.
|
||||
* @draft ICU 62
|
||||
*/
|
||||
virtual void setScale(int32_t newValue);
|
||||
virtual void setMultiplierScale(int32_t newValue);
|
||||
|
||||
/**
|
||||
* Get the rounding increment.
|
||||
|
|
|
@ -1018,6 +1018,8 @@ typedef enum UNumberFormatAttribute {
|
|||
* <p>Example: setting the scale to 3, 123 formats as "123,000"
|
||||
* <p>Example: setting the scale to -4, 123 formats as "0.0123"
|
||||
*
|
||||
* This setting is analogous to getMultiplierScale() and setMultiplierScale() in decimfmt.h.
|
||||
*
|
||||
* @stable ICU 51 */
|
||||
UNUM_SCALE = 21,
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
|
|
|
@ -612,9 +612,9 @@ void IntlTestDecimalFormatAPI::TestScale()
|
|||
// Test both the attribute and the setter
|
||||
if (i % 2 == 0) {
|
||||
pat.setAttribute(UNUM_SCALE, testData[i].inputScale,status);
|
||||
assertEquals("", testData[i].inputScale, pat.getScale());
|
||||
assertEquals("", testData[i].inputScale, pat.getMultiplierScale());
|
||||
} else {
|
||||
pat.setScale(testData[i].inputScale);
|
||||
pat.setMultiplierScale(testData[i].inputScale);
|
||||
assertEquals("", testData[i].inputScale, pat.getAttribute(UNUM_SCALE, status));
|
||||
}
|
||||
pat.format(testData[i].inputValue, resultStr);
|
||||
|
|
|
@ -656,6 +656,7 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n
|
|||
TESTCASE_AUTO(Test11035_FormatCurrencyAmount);
|
||||
TESTCASE_AUTO(Test11318_DoubleConversion);
|
||||
TESTCASE_AUTO(TestParsePercentRegression);
|
||||
TESTCASE_AUTO(TestMultiplierWithScale);
|
||||
TESTCASE_AUTO_END;
|
||||
}
|
||||
|
||||
|
@ -9061,4 +9062,14 @@ void NumberFormatTest::TestParsePercentRegression() {
|
|||
}
|
||||
}
|
||||
|
||||
void NumberFormatTest::TestMultiplierWithScale() {
|
||||
IcuTestErrorCode status(*this, "TestMultiplierWithScale");
|
||||
|
||||
// Test magnitude combined with multiplier, as shown in API docs
|
||||
DecimalFormat df("0", {"en", status}, status);
|
||||
df.setMultiplier(5);
|
||||
df.setMultiplierScale(-1);
|
||||
expect2(df, 100, u"50"); // round-trip test
|
||||
}
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
|
|
@ -223,6 +223,7 @@ class NumberFormatTest: public CalendarTimeZoneTest {
|
|||
void Test11035_FormatCurrencyAmount();
|
||||
void Test11318_DoubleConversion();
|
||||
void TestParsePercentRegression();
|
||||
void TestMultiplierWithScale();
|
||||
|
||||
private:
|
||||
UBool testFormattableAsUFormattable(const char *file, int line, Formattable &f);
|
||||
|
|
Loading…
Add table
Reference in a new issue