SOURCE CODE FILES FOR DecimalFormat EXAMPLE DecimalFormat =============================================================================== /** * Project DecimalFormat * Class DecimalFormat * * Use a DecimalFormat object for formatting values. */ import java.text.DecimalFormat; public class Main { public static void main(String[] args) { // The DecimalFormat object df returns a // String object with the double value // formatted with two digits after the // decimal point. DecimalFormat df = new DecimalFormat("#0.00"); // Initialize the double variables. double x = 34.456543, y = 18271.9, z = 0.0328; // Format and print the variables. System.out.println(df.format(x) + " " + df.format(y) + " " + df.format(z)); } } // Output: 34.46 18271.90 0.03 ===============================================================================