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