JDK-8235942 : Support monetary grouping separator in DecimalFormat/DecimalFormatSymbols
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.text
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 15
  • Submitted: 2019-12-13
  • Updated: 2020-01-06
  • Resolved: 2020-01-06
Related Reports
CSR :  
Description
Summary
-------

Grouping separator in ```java.text.DecimalFormat/DecimalFormatSymbols``` should identify generic and monetary instances.

Problem
-------

Some languages have two distinct characters for the grouping separator. For example, the number ```1_500``` should be formatted to ```"1 500"``` as a generic number, and ```"1.500"``` for currency in German in Austria. Currently, JDK assumes there is one single character for the grouping separator per locale, so it cannot handle the de-AT case.

Solution
--------

A monetary grouping separator is added to ```DecimalFormatSymbols```. It is used in ```DecimalFormat``` for patterns with a currency sign symbol ```U+00A4```. Public get and set methods should be provided for applications, which will be on par with ```get/setMonetaryDecimalSeparator()``` methods. Initial values for the field will be obtained from the CLDR locale data.

Specification
-------------
In ```java.text.DecimalFormat``` class description, change the following rows in the chart of "Special Pattern Characters":

The "Meaning" column of ',' should read:

    Grouping separator or monetary grouping separator

The "Meaning" column of ```¤ (\u00A4)``` should read:

    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.

Add the following new getter/setter methods in ```java.text.DecimalFormatSymbols``` class:

    /**
     * Gets the character used for grouping separator for currencies.
     * May be different from {@code grouping separator} in some locales,
     * e.g, German in Austria.
     *
     * @since 15
     * @return the monetary grouping separator
     */
    public char getMonetaryGroupingSeparator()
    
     /**
     * Sets the character used for grouping separator for currencies.
     * Invocation of this method will not affect the normal
     * {@code grouping separator}.
     *
     * @param monetaryGroupingSeparator the monetary grouping separator
     * @see #setGroupingSeparator(char)
     * @since 15
     */
    public void setMonetaryGroupingSeparator(char monetaryGroupingSeparator)

Add the following new serializable field in ```java.text.DecimalFormatSymbols``` class:

    /**
     * The grouping separator used when formatting currency values.
     *
     * @serial
     * @since 15
     */
    private  char    monetaryGroupingSeparator;

Add the following sentence in the method description of ```java.text.DecimalFormatSymbols.readObject()```, after the ```perMillText```, ```percentText```, ```minusSignText``` explanation :

     * If {@code serialVersionOnStream} is less than 5, it initializes
     * {@code monetaryGroupingSeparator} using {@code groupingSeparator}.

Add the following list item in the field description of ```java.text.DecimalFormatSymbols.serialVersionOnStream```, after the ```perMillText```, ```percentText```, ```minusSignText``` list item:

     * <li><b>5</b>: Versions written by Java SE 15 or later, which include
     *      new {@code monetaryGroupingSeparator} field.

Replace the occurrences of "thousand separator(s)" with "grouping separator(s)" in ```DecimalFormat``` and ```DecimalFormatSymbols``` classes, as the former is old (and incorrect) usage of the separator name.

Comments
Moving to Approved.
06-01-2020