< prev index next >

src/java.base/share/classes/java/util/Formatter.java

Print this page

        

*** 45,54 **** --- 45,55 ---- import java.nio.charset.UnsupportedCharsetException; import java.text.DateFormatSymbols; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; + import java.text.spi.NumberFormatProvider; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.Objects; import java.time.DateTimeException;
*** 60,69 **** --- 61,72 ---- import java.time.temporal.TemporalQueries; import java.time.temporal.UnsupportedTemporalTypeException; import jdk.internal.math.DoubleConsts; import jdk.internal.math.FormattedFloatingDecimal; + import sun.util.locale.provider.LocaleProviderAdapter; + import sun.util.locale.provider.ResourceBundleBasedAdapter; /** * An interpreter for printf-style format strings. This class provides support * for layout justification and alignment, common formats for numeric, string, * and date/time data, and locale-specific output. Common Java types such as
*** 4474,4485 **** grpSep = ','; grpSize = 3; } else { DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l); grpSep = dfs.getGroupingSeparator(); ! DecimalFormat df = (DecimalFormat) NumberFormat.getIntegerInstance(l); grpSize = df.getGroupingSize(); } } // localize the digits inserting group separators as necessary for (int j = offset; j < len; j++) { --- 4477,4513 ---- grpSep = ','; grpSize = 3; } else { DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l); grpSep = dfs.getGroupingSeparator(); ! DecimalFormat df = null; ! NumberFormat nf = NumberFormat.getNumberInstance(l); ! if (nf instanceof DecimalFormat) { ! df = (DecimalFormat) nf; ! } else { ! ! // Use DecimalFormat constructor to obtain the instance, ! // in case NumberFormat.getNumberInstance(l) ! // returns instance other than DecimalFormat ! LocaleProviderAdapter adapter = LocaleProviderAdapter ! .getAdapter(NumberFormatProvider.class, l); ! if (!(adapter instanceof ResourceBundleBasedAdapter)) { ! adapter = LocaleProviderAdapter.getResourceBundleBased(); ! } ! String[] all = adapter.getLocaleResources(l) ! .getNumberPatterns(); ! df = new DecimalFormat(all[0], dfs); ! } grpSize = df.getGroupingSize(); + // Some locales do not use grouping (the number + // pattern for these locales does not contain group, e.g. + // ("#0.###")), but specify a grouping separator. + // To avoid unnecessary identification of the position of + // grouping separator, reset its value with null character + if (!df.isGroupingUsed() || grpSize == 0) { + grpSep = '\0'; + } } } // localize the digits inserting group separators as necessary for (int j = offset; j < len; j++) {
< prev index next >