]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.trend/example/org/simantics/trend/DecimalFormatDemo.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.trend / example / org / simantics / trend / DecimalFormatDemo.java
diff --git a/bundles/org.simantics.trend/example/org/simantics/trend/DecimalFormatDemo.java b/bundles/org.simantics.trend/example/org/simantics/trend/DecimalFormatDemo.java
new file mode 100644 (file)
index 0000000..2a18e39
--- /dev/null
@@ -0,0 +1,65 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.trend;\r
+\r
+import java.util.*;\r
+import java.text.*;\r
\r
+public class DecimalFormatDemo {\r
\r
+   static public void customFormat(String pattern, double value ) {\r
+      DecimalFormat myFormatter = new DecimalFormat(pattern);\r
+      String output = myFormatter.format(value);\r
+      System.out.println(value + "  " + pattern + "  " + output);\r
+   }\r
\r
+   static public void localizedFormat(String pattern, double value, \r
+                                      Locale loc ) {\r
+      NumberFormat nf = NumberFormat.getNumberInstance(loc);\r
+      DecimalFormat df = (DecimalFormat)nf;\r
+      df.applyPattern(pattern);\r
+      String output = df.format(value);\r
+      System.out.println(pattern + "  " + output + "  " + loc.toString());\r
+   }\r
\r
+   static public void main(String[] args) {\r
\r
+      customFormat("###,###.###", 123456.789);\r
+      customFormat("###.##", 123456.789);\r
+      customFormat("000000.000", 123.78);\r
+      customFormat("$###,###.###", 12345.67);\r
+      customFormat("\u00a5###,###.###", 12345.67);\r
\r
+      Locale currentLocale = new Locale("en", "US");\r
\r
+      DecimalFormatSymbols unusualSymbols = \r
+         new DecimalFormatSymbols(currentLocale);\r
+      unusualSymbols.setDecimalSeparator('|');\r
+      unusualSymbols.setGroupingSeparator('^');\r
+      String strange = "#,##0.###";\r
+      DecimalFormat weirdFormatter = new DecimalFormat(strange, unusualSymbols);\r
+      weirdFormatter.setGroupingSize(4);\r
+      String bizarre = weirdFormatter.format(12345.678);\r
+      System.out.println(bizarre);\r
\r
+      Locale[] locales = {\r
+         new Locale("en", "US"),\r
+         new Locale("de", "DE"),\r
+         new Locale("fr", "FR")\r
+      };\r
\r
+      for (int i = 0; i < locales.length; i++) {\r
+         localizedFormat("###,###.###", 123456.789, locales[i]);\r
+      }\r
\r
+   }\r
+}
\ No newline at end of file