X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.trend%2Fexample%2Forg%2Fsimantics%2Ftrend%2FTestDecimalFormat.java;h=343789335658e5181e04ec75917f770465423dcc;hb=refs%2Fchanges%2F38%2F238%2F2;hp=e541de85bdc0448974357b0d600c785021f9dfd6;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.trend/example/org/simantics/trend/TestDecimalFormat.java b/bundles/org.simantics.trend/example/org/simantics/trend/TestDecimalFormat.java index e541de85b..343789335 100644 --- a/bundles/org.simantics.trend/example/org/simantics/trend/TestDecimalFormat.java +++ b/bundles/org.simantics.trend/example/org/simantics/trend/TestDecimalFormat.java @@ -1,94 +1,94 @@ -/******************************************************************************* - * 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.math.BigDecimal; -import java.text.Format; -import java.text.NumberFormat; - -import org.simantics.utils.format.FormattingUtils; -import org.simantics.utils.format.ValueFormat; - -public class TestDecimalFormat { - - public static void main(String[] args) { - - - NumberFormat f = ValueFormat.Scientific.format; - double x = 0.00001234567890; - for (int i=-10; i<10; i++) { - System.out.println(f.format(x)); - x *= 10.; - } - - x = 6.00; - for (int i=0; i<10; i++) { - x+= 0.0000000000001; - System.out.println(x); - } - - BigDecimal dec = new BigDecimal(0); - BigDecimal augend = new BigDecimal(String.valueOf(0.2)); - System.out.println(new BigDecimal(0.2)); - System.out.println(new BigDecimal(String.valueOf(0.2))); - for (int i=0; i<1000000; i++) { - dec = dec.add(augend); - String s1 = dec.toString(); - String s2 = Double.toString(dec.doubleValue()); - if (!s1.equals(s2)) { - System.out.println(s1 + " vs. " + s2); - } - } - - Format format = FormattingUtils.significantDigitFormat(7); - - System.out.println(format.format(123456789012345.1234)); - System.out.println(format.format(12345678901.23451234)); - System.out.println(format.format(1234567890.123451234)); - System.out.println(format.format(123456789.0123451234)); - System.out.println(format.format(12345678.90123451234)); - System.out.println(format.format(10000123.4)); - System.out.println(format.format(9999999.99)); - System.out.println(format.format(9999999.9)); - System.out.println(format.format(9999999)); - System.out.println(format.format(1234567.890123451234)); - System.out.println(format.format(123456.7890123451234)); - System.out.println(format.format(12345.67890123451234)); - System.out.println(format.format(1234.567890123451234)); - System.out.println(format.format(123.4567890123451234)); - System.out.println(format.format(12.34567890123451234)); - System.out.println(format.format(1.234567890123451234)); - System.out.println(format.format(0.1234567890123451234)); - System.out.println(format.format(0.1111111)); - System.out.println(format.format(0.1000001)); - System.out.println(format.format(0.09999999999)); - System.out.println(format.format(0.0999999999)); - System.out.println(format.format(0.099999999)); - System.out.println(format.format(0.09999999)); - System.out.println(format.format(0.0999999)); - System.out.println(format.format(0.01234567890123451234)); - System.out.println(format.format(0.001234567890123451234)); - System.out.println(format.format(0.0001234567890123451234)); - System.out.println(format.format(0.00001234567890123451234)); - System.out.println(format.format(0.000001234567890123451234)); - System.out.println(format.format(0.0000001234567890123451234)); - System.out.println(format.format(0.00000001234567890123451234)); - System.out.println(format.format(0.000000001234567890123451234)); - - System.out.println(format.format(10)); - System.out.println(format.format(20L)); - System.out.println(format.format(-0)); - System.out.println(format.format(-1L)); - - } - -} +/******************************************************************************* + * 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.math.BigDecimal; +import java.text.Format; +import java.text.NumberFormat; + +import org.simantics.utils.format.FormattingUtils; +import org.simantics.utils.format.ValueFormat; + +public class TestDecimalFormat { + + public static void main(String[] args) { + + + NumberFormat f = ValueFormat.Scientific.format; + double x = 0.00001234567890; + for (int i=-10; i<10; i++) { + System.out.println(f.format(x)); + x *= 10.; + } + + x = 6.00; + for (int i=0; i<10; i++) { + x+= 0.0000000000001; + System.out.println(x); + } + + BigDecimal dec = new BigDecimal(0); + BigDecimal augend = new BigDecimal(String.valueOf(0.2)); + System.out.println(new BigDecimal(0.2)); + System.out.println(new BigDecimal(String.valueOf(0.2))); + for (int i=0; i<1000000; i++) { + dec = dec.add(augend); + String s1 = dec.toString(); + String s2 = Double.toString(dec.doubleValue()); + if (!s1.equals(s2)) { + System.out.println(s1 + " vs. " + s2); + } + } + + Format format = FormattingUtils.significantDigitFormat(7); + + System.out.println(format.format(123456789012345.1234)); + System.out.println(format.format(12345678901.23451234)); + System.out.println(format.format(1234567890.123451234)); + System.out.println(format.format(123456789.0123451234)); + System.out.println(format.format(12345678.90123451234)); + System.out.println(format.format(10000123.4)); + System.out.println(format.format(9999999.99)); + System.out.println(format.format(9999999.9)); + System.out.println(format.format(9999999)); + System.out.println(format.format(1234567.890123451234)); + System.out.println(format.format(123456.7890123451234)); + System.out.println(format.format(12345.67890123451234)); + System.out.println(format.format(1234.567890123451234)); + System.out.println(format.format(123.4567890123451234)); + System.out.println(format.format(12.34567890123451234)); + System.out.println(format.format(1.234567890123451234)); + System.out.println(format.format(0.1234567890123451234)); + System.out.println(format.format(0.1111111)); + System.out.println(format.format(0.1000001)); + System.out.println(format.format(0.09999999999)); + System.out.println(format.format(0.0999999999)); + System.out.println(format.format(0.099999999)); + System.out.println(format.format(0.09999999)); + System.out.println(format.format(0.0999999)); + System.out.println(format.format(0.01234567890123451234)); + System.out.println(format.format(0.001234567890123451234)); + System.out.println(format.format(0.0001234567890123451234)); + System.out.println(format.format(0.00001234567890123451234)); + System.out.println(format.format(0.000001234567890123451234)); + System.out.println(format.format(0.0000001234567890123451234)); + System.out.println(format.format(0.00000001234567890123451234)); + System.out.println(format.format(0.000000001234567890123451234)); + + System.out.println(format.format(10)); + System.out.println(format.format(20L)); + System.out.println(format.format(-0)); + System.out.println(format.format(-1L)); + + } + +}