View | Details | Raw Unified | Return to bug 59638
Collapse All | Expand All

(-)a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java (-6 / +11 lines)
Lines 674-686 public class DataFormatter implements Observer { Link Here
674
        // eg for a format like #'##0 which wants 12'345 not 12,345
674
        // eg for a format like #'##0 which wants 12'345 not 12,345
675
        Matcher agm = alternateGrouping.matcher(format);
675
        Matcher agm = alternateGrouping.matcher(format);
676
        if (agm.find()) {
676
        if (agm.find()) {
677
            symbols = DecimalFormatSymbols.getInstance(locale);
678
            
679
            char grouping = agm.group(2).charAt(0);
677
            char grouping = agm.group(2).charAt(0);
680
            symbols.setGroupingSeparator(grouping);
678
            // Only replace the grouping character if it is not the default
681
            String oldPart = agm.group(1);
679
            // grouping character for the US locale (',') in order to enable
682
            String newPart = oldPart.replace(grouping, ',');
680
            // correct grouping for non-US locales.
683
            format = format.replace(oldPart, newPart);
681
            if (grouping!=',') {
682
                symbols = DecimalFormatSymbols.getInstance(locale);
683
684
                symbols.setGroupingSeparator(grouping);
685
                String oldPart = agm.group(1);
686
                String newPart = oldPart.replace(grouping, ',');
687
                format = format.replace(oldPart, newPart);
688
            }
684
        }
689
        }
685
        
690
        
686
        try {
691
        try {
(-)a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java (+19 lines)
Lines 82-87 public class TestDataFormatter { Link Here
82
82
83
    }
83
    }
84
84
85
86
    /**
87
     * Test that we use the specified locale when deciding
88
     *   how to format normal numbers
89
     */
90
    @Test
91
    public void testGrouping() {
92
        DataFormatter dfUS = new DataFormatter(Locale.US);
93
        DataFormatter dfDE = new DataFormatter(Locale.GERMAN);
94
95
        assertEquals("1,234.57", dfUS.formatRawCellContents(1234.567, -1, "#,##0.00"));
96
        assertEquals("1'234.57", dfUS.formatRawCellContents(1234.567, -1, "#'##0.00"));
97
        assertEquals("1 234.57", dfUS.formatRawCellContents(1234.567, -1, "# ##0.00"));
98
99
        assertEquals("1.234,57", dfDE.formatRawCellContents(1234.567, -1, "#,##0.00"));
100
        assertEquals("1'234,57", dfDE.formatRawCellContents(1234.567, -1, "#'##0.00"));
101
        assertEquals("1 234,57", dfDE.formatRawCellContents(1234.567, -1, "# ##0.00"));
102
    }
103
85
    /**
104
    /**
86
     * Ensure that colours get correctly
105
     * Ensure that colours get correctly
87
     *  zapped from within the format strings
106
     *  zapped from within the format strings

Return to bug 59638