}
public static Format significantDigitFormat(int withSignificantDigits) {
- return significantDigitFormat(withSignificantDigits, false);
+ return significantDigitFormat(Locale.getDefault(Locale.Category.FORMAT), withSignificantDigits);
+ }
+
+ public static Format significantDigitFormat(Locale locale, int withSignificantDigits) {
+ return significantDigitFormat(locale, withSignificantDigits, false);
}
public static Format significantDigitFormat(int withSignificantDigits, boolean stripTrailingZeros) {
+ return significantDigitFormat(Locale.getDefault(Locale.Category.FORMAT), withSignificantDigits, stripTrailingZeros);
+ }
+
+ public static Format significantDigitFormat(Locale locale, int withSignificantDigits, boolean stripTrailingZeros) {
if (withSignificantDigits < 1)
throw new IllegalArgumentException("withSignificantDigits must be > 0, got " + withSignificantDigits);
StringBuilder sb = new StringBuilder(withSignificantDigits + 3);
for (int i = 0; i < withSignificantDigits-1; i++)
sb.append("#");
sb.append("E0");
- NumberFormat low = new DecimalFormat(sb.toString());
+ NumberFormat low = new DecimalFormat(sb.toString(), DecimalFormatSymbols.getInstance(locale));
low.setGroupingUsed(false);
- NumberFormat hi = new SignificantDigitFormat(withSignificantDigits, stripTrailingZeros);
+ NumberFormat hi = new SignificantDigitFormat(locale, withSignificantDigits, stripTrailingZeros);
Format format = new SwitchFormat(0.1, 1, low, hi, hi);
return format;
}
private boolean fixDecimalSeparator;
private char decimalSeparator;
- public SignificantDigitFormat(int digits, boolean stripTrailingZeros) {
+ public SignificantDigitFormat(Locale locale, int digits, boolean stripTrailingZeros) {
this.mc = new MathContext(digits);
this.stripTrailingZeros = stripTrailingZeros;
- DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
+ DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
decimalSeparator = symbols.getDecimalSeparator();
// BigDecimal always formats doubles with '.' as decimal separator.
if (decimalSeparator != '.')