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