1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.trend;
17 public class DecimalFormatDemo {
19 static public void customFormat(String pattern, double value ) {
20 DecimalFormat myFormatter = new DecimalFormat(pattern);
21 String output = myFormatter.format(value);
22 System.out.println(value + " " + pattern + " " + output);
25 static public void localizedFormat(String pattern, double value,
27 NumberFormat nf = NumberFormat.getNumberInstance(loc);
28 DecimalFormat df = (DecimalFormat)nf;
29 df.applyPattern(pattern);
30 String output = df.format(value);
31 System.out.println(pattern + " " + output + " " + loc.toString());
34 static public void main(String[] args) {
36 customFormat("###,###.###", 123456.789);
37 customFormat("###.##", 123456.789);
38 customFormat("000000.000", 123.78);
39 customFormat("$###,###.###", 12345.67);
40 customFormat("\u00a5###,###.###", 12345.67);
42 Locale currentLocale = new Locale("en", "US");
44 DecimalFormatSymbols unusualSymbols =
45 new DecimalFormatSymbols(currentLocale);
46 unusualSymbols.setDecimalSeparator('|');
47 unusualSymbols.setGroupingSeparator('^');
48 String strange = "#,##0.###";
49 DecimalFormat weirdFormatter = new DecimalFormat(strange, unusualSymbols);
50 weirdFormatter.setGroupingSize(4);
51 String bizarre = weirdFormatter.format(12345.678);
52 System.out.println(bizarre);
55 new Locale("en", "US"),
56 new Locale("de", "DE"),
57 new Locale("fr", "FR")
60 for (int i = 0; i < locales.length; i++) {
61 localizedFormat("###,###.###", 123456.789, locales[i]);