import java.text.*; /** Formatting real numbers with DecimalFormat. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * © 2001 Marty Hall and Larry Brown; * may be freely used or adapted. */ public class NumFormat { public static void main (String[] args) { DecimalFormat science = new DecimalFormat("0.000E0"); DecimalFormat plain = new DecimalFormat("0.0000"); for(double d=100.0; d<140.0; d*=1.10) { System.out.println("Scientific: " + science.format(d) + " and Plain: " + plain.format(d)); } } }
Aug 29