mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8227313: Support monetary grouping separator in DecimalFormat/DecimalFormatSymbols
Reviewed-by: joehw
This commit is contained in:
parent
8a1b5ad914
commit
2e237e35fd
7 changed files with 370 additions and 192 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
|
@ -136,14 +136,14 @@ import sun.util.locale.provider.ResourceBundleBasedAdapter;
|
|||
* 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
|
||||
* 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 thousands
|
||||
* 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
|
||||
|
@ -203,7 +203,7 @@ import sun.util.locale.provider.ResourceBundleBasedAdapter;
|
|||
* <th scope="row">{@code ,}
|
||||
* <td>Number
|
||||
* <td>Yes
|
||||
* <td>Grouping separator
|
||||
* <td>Grouping separator or monetary grouping separator
|
||||
* <tr style="vertical-align: top">
|
||||
* <th scope="row">{@code E}
|
||||
* <td>Number
|
||||
|
@ -231,8 +231,8 @@ import sun.util.locale.provider.ResourceBundleBasedAdapter;
|
|||
* <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.
|
||||
* 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
|
||||
|
@ -1103,7 +1103,9 @@ public class DecimalFormat extends NumberFormat {
|
|||
// 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();
|
||||
fastPathData.groupingChar = isCurrencyFormat ?
|
||||
symbols.getMonetaryGroupingSeparator() :
|
||||
symbols.getGroupingSeparator();
|
||||
|
||||
// Sets up fractional constants related to currency/decimal pattern.
|
||||
fastPathData.fractionalMaxIntBound = (isCurrencyFormat)
|
||||
|
@ -1774,7 +1776,9 @@ public class DecimalFormat extends NumberFormat {
|
|||
int maxIntDigits, int minIntDigits,
|
||||
int maxFraDigits, int minFraDigits) {
|
||||
|
||||
char grouping = symbols.getGroupingSeparator();
|
||||
char grouping = isCurrencyFormat ?
|
||||
symbols.getMonetaryGroupingSeparator() :
|
||||
symbols.getGroupingSeparator();
|
||||
char zero = symbols.getZeroDigit();
|
||||
int zeroDelta = zero - '0'; // '0' is the DigitList representation of zero
|
||||
|
||||
|
@ -2393,7 +2397,9 @@ public class DecimalFormat extends NumberFormat {
|
|||
char decimal = isCurrencyFormat ?
|
||||
symbols.getMonetaryDecimalSeparator() :
|
||||
symbols.getDecimalSeparator();
|
||||
char grouping = symbols.getGroupingSeparator();
|
||||
char grouping = isCurrencyFormat ?
|
||||
symbols.getMonetaryGroupingSeparator() :
|
||||
symbols.getGroupingSeparator();
|
||||
String exponentString = symbols.getExponentSeparator();
|
||||
boolean sawDecimal = false;
|
||||
boolean sawExponent = false;
|
||||
|
@ -4061,7 +4067,7 @@ public class DecimalFormat extends NumberFormat {
|
|||
|
||||
/**
|
||||
* True if this object represents a currency format. This determines
|
||||
* whether the monetary decimal separator is used instead of the normal one.
|
||||
* whether the monetary decimal/grouping separators are used instead of the normal ones.
|
||||
*/
|
||||
private transient boolean isCurrencyFormat = false;
|
||||
|
||||
|
@ -4346,8 +4352,8 @@ public class DecimalFormat extends NumberFormat {
|
|||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue