]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Allow specification of Locale to FormattingUtils.significantDigitFormat 45/245/3
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 3 Jan 2017 08:35:48 +0000 (10:35 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 3 Jan 2017 08:45:38 +0000 (10:45 +0200)
refs #6929

Change-Id: I67b9192ebe8113e44fdbee6d089dbef58b59bc39

bundles/org.simantics.utils/src/org/simantics/utils/format/FormattingUtils.java

index 11d37e305ef2413842ae1a3cb249c582bb3491c2..be31244dae39d7383537a98bc83909f524761e77 100644 (file)
@@ -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 != '.')