static const UChar gLastResortPluralCurrencyPat[] = {
0x23, 0x30, 0x2E, 0x30, 0x30, 0xA0, 0xA4, 0xA4, 0xA4, 0 /* "#0.00\u00A0\u00A4\u00A4\u00A4*/
};
+static const UChar gLastResortAccountingCurrencyPat[] = {
+ 0xA4, 0x23, 0x30, 0x2E, 0x30, 0x30, 0x3B, 0x28, 0xA4, 0x23, 0x30, 0x2E, 0x30, 0x30, 0x29, 0 /* "\u00A4#0.00;(\u00A4#0.00)" */
+};
static const UChar gSingleCurrencySign[] = {0xA4, 0};
static const UChar gDoubleCurrencySign[] = {0xA4, 0xA4, 0};
NULL, // UNUM_NUMBERING_SYSTEM
NULL, // UNUM_PATTERN_RULEBASED
gLastResortIsoCurrencyPat, // UNUM_CURRENCY_ISO
- gLastResortPluralCurrencyPat // UNUM_CURRENCY_PLURAL
+ gLastResortPluralCurrencyPat, // UNUM_CURRENCY_PLURAL
+ gLastResortAccountingCurrencyPat // UNUM_CURRENCY_ACCOUNTING
};
// Keys used for accessing resource bundles
// except for replacing the single currency sign with
// double currency sign or triple currency sign.
"currencyFormat", // UNUM_CURRENCY_ISO
- "currencyFormat" // UNUM_CURRENCY_PLURAL
+ "currencyFormat", // UNUM_CURRENCY_PLURAL
+ "accountingFormat" // UNUM_CURRENCY_ACCOUNTING
};
static icu::LRUCache *gNumberFormatCache = NULL;
case UNUM_CURRENCY:
case UNUM_CURRENCY_ISO: // do not support plural formatting here
case UNUM_CURRENCY_PLURAL:
+ case UNUM_CURRENCY_ACCOUNTING:
f = new Win32NumberFormat(desiredLocale, curr, status);
if (U_SUCCESS(status)) {
if (U_FAILURE(status)) {
return NULL;
}
- if(style==UNUM_CURRENCY || style == UNUM_CURRENCY_ISO){
+ if(style==UNUM_CURRENCY || style == UNUM_CURRENCY_ISO || style == UNUM_CURRENCY_ACCOUNTING){
const UChar* currPattern = symbolsToAdopt->getCurrencyPattern();
if(currPattern!=NULL){
pattern.setTo(currPattern, u_strlen(currPattern));
* @stable ICU 4.8
*/
UNUM_CURRENCY_PLURAL,
+ /**
+ * Currency format for accounting, e.g., "($3.00)" for
+ * negative currency amount instead of "-$3.00" ({@link #UNUM_CURRENCY}).
+ * @draft ICU 53
+ */
+ UNUM_CURRENCY_ACCOUNTING,
/**
* One more than the highest number format style constant.
* @stable ICU 4.8
case UNUM_SCIENTIFIC:
case UNUM_CURRENCY_ISO:
case UNUM_CURRENCY_PLURAL:
+ case UNUM_CURRENCY_ACCOUNTING:
retVal = NumberFormat::createInstance(Locale(locale), style, *status);
break;
TESTCASE_AUTO(Test10468ApplyPattern);
TESTCASE_AUTO(TestRoundingScientific10542);
TESTCASE_AUTO(TestZeroScientific10547);
+ TESTCASE_AUTO(TestAccountingCurrency);
TESTCASE_AUTO_END;
}
}
void NumberFormatTest::expect(NumberFormat* fmt, const Formattable& n,
- const UnicodeString& exp,
+ const UnicodeString& exp, UBool rt,
UErrorCode status) {
if (fmt == NULL || U_FAILURE(status)) {
dataerrln("FAIL: NumberFormat constructor");
} else {
- expect(*fmt, n, exp);
+ expect(*fmt, n, exp, rt);
}
delete fmt;
}
}
}
+void NumberFormatTest::TestAccountingCurrency() {
+ UErrorCode status = U_ZERO_ERROR;
+ UNumberFormatStyle style = UNUM_CURRENCY_ACCOUNTING;
+
+ expect(NumberFormat::createInstance("en_US", style, status),
+ (Formattable)1234.5, "$1,234.50", TRUE, status);
+ expect(NumberFormat::createInstance("en_US", style, status),
+ (Formattable)-1234.5, "($1,234.50)", TRUE, status);
+ expect(NumberFormat::createInstance("en_US", style, status),
+ (Formattable)0, "$0.00", TRUE, status);
+ expect(NumberFormat::createInstance("en_US", style, status),
+ (Formattable)-0.2, "($0.20)", TRUE, status);
+ expect(NumberFormat::createInstance("ja_JP", style, status),
+ (Formattable)10000, UnicodeString("\\uFFE510,000").unescape(), TRUE, status);
+ expect(NumberFormat::createInstance("ja_JP", style, status),
+ (Formattable)-1000.5, UnicodeString("(\\uFFE51,000)").unescape(), FALSE, status);
+ expect(NumberFormat::createInstance("de_DE", style, status),
+ (Formattable)-23456.7, UnicodeString("-23.456,70\\u00A0\\u20AC").unescape(), TRUE, status);
+}
+
#endif /* #if !UCONFIG_NO_FORMATTING */
void Test10468ApplyPattern();
void TestRoundingScientific10542();
void TestZeroScientific10547();
+ void TestAccountingCurrency();
private:
UBool testFormattableAsUFormattable(const char *file, int line, Formattable &f);
}
void expect(NumberFormat* fmt, const Formattable& n,
- const UnicodeString& exp, UErrorCode);
+ const UnicodeString& exp, UBool rt, UErrorCode errorCode);
+
+ void expect(NumberFormat* fmt, const Formattable& n,
+ const char *exp, UBool rt, UErrorCode errorCode) {
+ expect(fmt, n, UnicodeString(exp, ""), rt, errorCode);
+ }
+
+ void expect(NumberFormat* fmt, const Formattable& n,
+ const UnicodeString& exp, UErrorCode errorCode) {
+ expect(fmt, n, exp, TRUE, errorCode);
+ }
void expect(NumberFormat* fmt, const Formattable& n,
const char *exp, UErrorCode errorCode) {
- expect(fmt, n, UnicodeString(exp, ""), errorCode);
+ expect(fmt, n, UnicodeString(exp, ""), TRUE, errorCode);
}
void expectCurrency(NumberFormat& nf, const Locale& locale,