< prev index next >
src/java.base/share/classes/java/text/DecimalFormat.java
Print this page
rev 57525 : 8227313: Support monetary grouping separator in DecimalFormat/DecimalFormatSymbols
Reviewed-by: joehw
*** 1,7 ****
/*
! * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 134,151 ****
* minimal digits, and other characteristics are all the same as the positive
* pattern. That means that {@code "#,##0.0#;(#)"} produces precisely
* the same behavior as {@code "#,##0.0#;(#,##0.0#)"}.
*
* <p>The prefixes, suffixes, and various symbols used for infinity, digits,
! * thousands separators, decimal separators, etc. may be set to arbitrary
* values, and they will appear properly during formatting. However, care must
* be taken that the symbols and strings do not conflict, or parsing will be
* unreliable. For example, either the positive and negative prefixes or the
* suffixes must be distinct for {@code DecimalFormat.parse()} to be able
* to distinguish positive from negative values. (If they are identical, then
* {@code DecimalFormat} will behave as if no negative subpattern was
! * specified.) Another example is that the decimal separator and thousands
* separator should be distinct characters, or parsing will be impossible.
*
* <p>The grouping separator is commonly used for thousands, but in some
* countries it separates ten-thousands. The grouping size is a constant number
* of digits between the grouping characters, such as 3 for 100,000,000 or 4 for
--- 134,151 ----
* minimal digits, and other characteristics are all the same as the positive
* pattern. That means that {@code "#,##0.0#;(#)"} produces precisely
* the same behavior as {@code "#,##0.0#;(#,##0.0#)"}.
*
* <p>The prefixes, suffixes, and various symbols used for infinity, digits,
! * grouping separators, decimal separators, etc. may be set to arbitrary
* values, and they will appear properly during formatting. However, care must
* be taken that the symbols and strings do not conflict, or parsing will be
* unreliable. For example, either the positive and negative prefixes or the
* suffixes must be distinct for {@code DecimalFormat.parse()} to be able
* to distinguish positive from negative values. (If they are identical, then
* {@code DecimalFormat} will behave as if no negative subpattern was
! * specified.) Another example is that the decimal separator and grouping
* separator should be distinct characters, or parsing will be impossible.
*
* <p>The grouping separator is commonly used for thousands, but in some
* countries it separates ten-thousands. The grouping size is a constant number
* of digits between the grouping characters, such as 3 for 100,000,000 or 4 for
*** 201,211 ****
* <td>Minus sign
* <tr style="vertical-align:top">
* <th scope="row">{@code ,}
* <td>Number
* <td>Yes
! * <td>Grouping separator
* <tr style="vertical-align: top">
* <th scope="row">{@code E}
* <td>Number
* <td>Yes
* <td>Separates mantissa and exponent in scientific notation.
--- 201,211 ----
* <td>Minus sign
* <tr style="vertical-align:top">
* <th scope="row">{@code ,}
* <td>Number
* <td>Yes
! * <td>Grouping separator or monetary grouping separator
* <tr style="vertical-align: top">
* <th scope="row">{@code E}
* <td>Number
* <td>Yes
* <td>Separates mantissa and exponent in scientific notation.
*** 229,240 ****
* <th scope="row">{@code ¤} ({@code \u00A4})
* <td>Prefix or suffix
* <td>No
* <td>Currency sign, replaced by currency symbol. If
* doubled, replaced by international currency symbol.
! * If present in a pattern, the monetary decimal separator
! * is used instead of the decimal separator.
* <tr style="vertical-align:top">
* <th scope="row">{@code '}
* <td>Prefix or suffix
* <td>No
* <td>Used to quote special characters in a prefix or suffix,
--- 229,240 ----
* <th scope="row">{@code ¤} ({@code \u00A4})
* <td>Prefix or suffix
* <td>No
* <td>Currency sign, replaced by currency symbol. If
* doubled, replaced by international currency symbol.
! * If present in a pattern, the monetary decimal/grouping separators
! * are used instead of the decimal/grouping separators.
* <tr style="vertical-align:top">
* <th scope="row">{@code '}
* <td>Prefix or suffix
* <td>No
* <td>Used to quote special characters in a prefix or suffix,
*** 1101,1111 ****
}
// Sets up the locale specific constants used when formatting.
// '0' is our default representation of zero.
fastPathData.zeroDelta = symbols.getZeroDigit() - '0';
! fastPathData.groupingChar = symbols.getGroupingSeparator();
// Sets up fractional constants related to currency/decimal pattern.
fastPathData.fractionalMaxIntBound = (isCurrencyFormat)
? 99 : 999;
fastPathData.fractionalScaleFactor = (isCurrencyFormat)
--- 1101,1113 ----
}
// Sets up the locale specific constants used when formatting.
// '0' is our default representation of zero.
fastPathData.zeroDelta = symbols.getZeroDigit() - '0';
! fastPathData.groupingChar = isCurrencyFormat ?
! symbols.getMonetaryGroupingSeparator() :
! symbols.getGroupingSeparator();
// Sets up fractional constants related to currency/decimal pattern.
fastPathData.fractionalMaxIntBound = (isCurrencyFormat)
? 99 : 999;
fastPathData.fractionalScaleFactor = (isCurrencyFormat)
*** 1772,1782 ****
void subformatNumber(StringBuffer result, FieldDelegate delegate,
boolean isNegative, boolean isInteger,
int maxIntDigits, int minIntDigits,
int maxFraDigits, int minFraDigits) {
! char grouping = symbols.getGroupingSeparator();
char zero = symbols.getZeroDigit();
int zeroDelta = zero - '0'; // '0' is the DigitList representation of zero
char decimal = isCurrencyFormat ?
symbols.getMonetaryDecimalSeparator() :
--- 1774,1786 ----
void subformatNumber(StringBuffer result, FieldDelegate delegate,
boolean isNegative, boolean isInteger,
int maxIntDigits, int minIntDigits,
int maxFraDigits, int minFraDigits) {
! char grouping = isCurrencyFormat ?
! symbols.getMonetaryGroupingSeparator() :
! symbols.getGroupingSeparator();
char zero = symbols.getZeroDigit();
int zeroDelta = zero - '0'; // '0' is the DigitList representation of zero
char decimal = isCurrencyFormat ?
symbols.getMonetaryDecimalSeparator() :
*** 2391,2401 ****
digits.decimalAt = digits.count = 0;
char zero = symbols.getZeroDigit();
char decimal = isCurrencyFormat ?
symbols.getMonetaryDecimalSeparator() :
symbols.getDecimalSeparator();
! char grouping = symbols.getGroupingSeparator();
String exponentString = symbols.getExponentSeparator();
boolean sawDecimal = false;
boolean sawExponent = false;
boolean sawDigit = false;
int exponent = 0; // Set to the exponent value, if any
--- 2395,2407 ----
digits.decimalAt = digits.count = 0;
char zero = symbols.getZeroDigit();
char decimal = isCurrencyFormat ?
symbols.getMonetaryDecimalSeparator() :
symbols.getDecimalSeparator();
! char grouping = isCurrencyFormat ?
! symbols.getMonetaryGroupingSeparator() :
! symbols.getGroupingSeparator();
String exponentString = symbols.getExponentSeparator();
boolean sawDecimal = false;
boolean sawExponent = false;
boolean sawDigit = false;
int exponent = 0; // Set to the exponent value, if any
*** 4059,4069 ****
private boolean parseBigDecimal = false;
/**
* True if this object represents a currency format. This determines
! * whether the monetary decimal separator is used instead of the normal one.
*/
private transient boolean isCurrencyFormat = false;
/**
* The {@code DecimalFormatSymbols} object used by this format.
--- 4065,4075 ----
private boolean parseBigDecimal = false;
/**
* True if this object represents a currency format. This determines
! * whether the monetary decimal/grouping separators are used instead of the normal ones.
*/
private transient boolean isCurrencyFormat = false;
/**
* The {@code DecimalFormatSymbols} object used by this format.
*** 4344,4355 ****
/**
* The CURRENCY_SIGN is the standard Unicode symbol for currency. It
* is used in patterns and substituted with either the currency symbol,
* or if it is doubled, with the international currency symbol. If the
! * CURRENCY_SIGN is seen in a pattern, then the decimal separator is
! * replaced with the monetary decimal separator.
*
* The CURRENCY_SIGN is not localized.
*/
private static final char CURRENCY_SIGN = '\u00A4';
--- 4350,4361 ----
/**
* The CURRENCY_SIGN is the standard Unicode symbol for currency. It
* is used in patterns and substituted with either the currency symbol,
* or if it is doubled, with the international currency symbol. If the
! * CURRENCY_SIGN is seen in a pattern, then the decimal/grouping separators
! * are replaced with the monetary decimal/grouping separators.
*
* The CURRENCY_SIGN is not localized.
*/
private static final char CURRENCY_SIGN = '\u00A4';
< prev index next >