What happened to printf or how do I format the numbers I need to print?
Location: http://www.jguru.com/faq/view.jsp?EID=8882 Created: Jan 26, 2000 Modified: 2000-01-26 01:22:50.759 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) The Java libraries and println() method provide no direct equivalent to printf/sprintf. While Acme labs provides an alternative at http://www.acme.com/java/software/Acme.Fmt.html, the NumberFormat class provides a mechanism for setting the number of characters to display before and after the decimal point. For instance, the following would print out a number with commas for the thousand, millions, billions, etc, at least one number after the decimal point, and at most two numbers (w/o rounding) after the decimal point. NumberFormat format = new DecimalFormat(“#,##0.0#”); System.out.println(format.format(0)); System.out.println(format.format(10000)); System.out.println(format.format(100000000)); System.out.println(format.format(25.25)); System.out.println(format.format(-10.125)); Running this would display: 0.0 1