]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.trend/example/org/simantics/trend/TestDecimalFormat.java
Some enhancements to GraphLayer-related utilities for Diagram layers
[simantics/platform.git] / bundles / org.simantics.trend / example / org / simantics / trend / TestDecimalFormat.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.trend;
13
14 import java.math.BigDecimal;
15 import java.text.Format;
16 import java.text.NumberFormat;
17
18 import org.simantics.utils.format.FormattingUtils;
19 import org.simantics.utils.format.ValueFormat;
20
21 public class TestDecimalFormat {
22
23         public static void main(String[] args) {
24         
25                 
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));
30                         x *= 10.;
31                 }
32                 
33                 x = 6.00;
34                 for (int i=0; i<10; i++) {
35                         x+= 0.0000000000001;
36                         System.out.println(x);
37                 }
38
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());
47                         if (!s1.equals(s2)) {
48                                 System.out.println(s1 + " vs. " + s2);
49                         }
50                 }
51
52                 Format format = FormattingUtils.significantDigitFormat(7);
53
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));
86
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));
91         
92         }
93         
94 }