X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.utils%2Fsrc%2Forg%2Fsimantics%2Futils%2Fformat%2FFormattingUtils.java;h=be31244dae39d7383537a98bc83909f524761e77;hb=988ec1a7ac7d5e6a354601635f2676935809d93c;hp=11d37e305ef2413842ae1a3cb249c582bb3491c2;hpb=a7eaa6a719acf77b115f48aeaab901ebedaf0a9b;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.utils/src/org/simantics/utils/format/FormattingUtils.java b/bundles/org.simantics.utils/src/org/simantics/utils/format/FormattingUtils.java index 11d37e305..be31244da 100644 --- a/bundles/org.simantics.utils/src/org/simantics/utils/format/FormattingUtils.java +++ b/bundles/org.simantics.utils/src/org/simantics/utils/format/FormattingUtils.java @@ -34,10 +34,18 @@ public class FormattingUtils { } 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); @@ -45,9 +53,9 @@ public class FormattingUtils { 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; } @@ -61,10 +69,10 @@ public class FormattingUtils { 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 != '.')