/******************************************************************************* * 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)); } }