Skip to content

Commit 3b23732

Browse files
author
duke
committedMar 14, 2022
Automatic merge of jdk:master into master
2 parents 5718bb1 + c96085e commit 3b23732

File tree

2 files changed

+68
-5
lines changed

2 files changed

+68
-5
lines changed
 

‎src/java.base/share/classes/java/text/DecimalFormat.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -3210,16 +3210,18 @@ private String toPattern(boolean localized) {
32103210
for (i = digitCount; i > 0; --i) {
32113211
if (i != digitCount && isGroupingUsed() && groupingSize != 0 &&
32123212
i % groupingSize == 0) {
3213-
result.append(localized ? symbols.getGroupingSeparator() :
3214-
PATTERN_GROUPING_SEPARATOR);
3213+
result.append(localized ?
3214+
(isCurrencyFormat ? symbols.getMonetaryGroupingSeparator() : symbols.getGroupingSeparator()) :
3215+
PATTERN_GROUPING_SEPARATOR);
32153216
}
32163217
result.append(i <= getMinimumIntegerDigits()
32173218
? (localized ? symbols.getZeroDigit() : PATTERN_ZERO_DIGIT)
32183219
: (localized ? symbols.getDigit() : PATTERN_DIGIT));
32193220
}
32203221
if (getMaximumFractionDigits() > 0 || decimalSeparatorAlwaysShown)
3221-
result.append(localized ? symbols.getDecimalSeparator() :
3222-
PATTERN_DECIMAL_SEPARATOR);
3222+
result.append(localized ?
3223+
(isCurrencyFormat ? symbols.getMonetaryDecimalSeparator() : symbols.getDecimalSeparator()) :
3224+
PATTERN_DECIMAL_SEPARATOR);
32233225
for (i = 0; i < getMaximumFractionDigits(); ++i) {
32243226
if (i < getMinimumFractionDigits()) {
32253227
result.append(localized ? symbols.getZeroDigit() :
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8282929
27+
* @summary Verifies that toLocalizedPattern() method correctly returns
28+
* monetary symbols in a currency formatter
29+
* @run testng ToLocalizedPatternTest
30+
*/
31+
32+
import static org.testng.Assert.assertEquals;
33+
import org.testng.annotations.Test;
34+
35+
import java.text.DecimalFormat;
36+
import java.text.DecimalFormatSymbols;
37+
import java.util.Locale;
38+
39+
@Test
40+
public class ToLocalizedPatternTest {
41+
private static final char MONETARY_GROUPING = 'g';
42+
private static final char MONETARY_DECIMAL = 'd';
43+
44+
public void testToLocalizedPattern() {
45+
var dfs = new DecimalFormatSymbols(Locale.US);
46+
47+
// Customize the decimal format symbols
48+
dfs.setMonetaryGroupingSeparator(MONETARY_GROUPING);
49+
dfs.setMonetaryDecimalSeparator(MONETARY_DECIMAL);
50+
51+
// create a currency formatter
52+
var cf = (DecimalFormat)DecimalFormat.getCurrencyInstance(Locale.US);
53+
cf.setDecimalFormatSymbols(dfs);
54+
55+
// check
56+
assertEquals(cf.toLocalizedPattern(),
57+
cf.toPattern()
58+
.replace(',', MONETARY_GROUPING)
59+
.replace('.', MONETARY_DECIMAL));
60+
}
61+
}

0 commit comments

Comments
 (0)
Please sign in to comment.