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;
14 import java.math.BigDecimal;
15 import java.text.Format;
16 import java.text.NumberFormat;
18 import org.simantics.utils.format.FormattingUtils;
19 import org.simantics.utils.format.ValueFormat;
21 public class TestDecimalFormat {
23 public static void main(String[] args) {
26 NumberFormat f = ValueFormat.Scientific.format;
27 double x = 0.00001234567890;
28 for (int i=-10; i<10; i++) {
29 System.out.println(f.format(x));
34 for (int i=0; i<10; i++) {
36 System.out.println(x);
39 BigDecimal dec = new BigDecimal(0);
40 BigDecimal augend = new BigDecimal(String.valueOf(0.2));
41 System.out.println(new BigDecimal(0.2));
42 System.out.println(new BigDecimal(String.valueOf(0.2)));
43 for (int i=0; i<1000000; i++) {
44 dec = dec.add(augend);
45 String s1 = dec.toString();
46 String s2 = Double.toString(dec.doubleValue());
48 System.out.println(s1 + " vs. " + s2);
52 Format format = FormattingUtils.significantDigitFormat(7);
54 System.out.println(format.format(123456789012345.1234));
55 System.out.println(format.format(12345678901.23451234));
56 System.out.println(format.format(1234567890.123451234));
57 System.out.println(format.format(123456789.0123451234));
58 System.out.println(format.format(12345678.90123451234));
59 System.out.println(format.format(10000123.4));
60 System.out.println(format.format(9999999.99));
61 System.out.println(format.format(9999999.9));
62 System.out.println(format.format(9999999));
63 System.out.println(format.format(1234567.890123451234));
64 System.out.println(format.format(123456.7890123451234));
65 System.out.println(format.format(12345.67890123451234));
66 System.out.println(format.format(1234.567890123451234));
67 System.out.println(format.format(123.4567890123451234));
68 System.out.println(format.format(12.34567890123451234));
69 System.out.println(format.format(1.234567890123451234));
70 System.out.println(format.format(0.1234567890123451234));
71 System.out.println(format.format(0.1111111));
72 System.out.println(format.format(0.1000001));
73 System.out.println(format.format(0.09999999999));
74 System.out.println(format.format(0.0999999999));
75 System.out.println(format.format(0.099999999));
76 System.out.println(format.format(0.09999999));
77 System.out.println(format.format(0.0999999));
78 System.out.println(format.format(0.01234567890123451234));
79 System.out.println(format.format(0.001234567890123451234));
80 System.out.println(format.format(0.0001234567890123451234));
81 System.out.println(format.format(0.00001234567890123451234));
82 System.out.println(format.format(0.000001234567890123451234));
83 System.out.println(format.format(0.0000001234567890123451234));
84 System.out.println(format.format(0.00000001234567890123451234));
85 System.out.println(format.format(0.000000001234567890123451234));
87 System.out.println(format.format(10));
88 System.out.println(format.format(20L));
89 System.out.println(format.format(-0));
90 System.out.println(format.format(-1L));