// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.text.DecimalFormat;

public class TwoDecimals {
   public static void main(String[] args) {
       double d1 = 123.456;
       double d2 = 123456;
       double d3 = 0.123456;
       DecimalFormat fmt1 = new DecimalFormat("0.00");
       DecimalFormat fmt2 = new DecimalFormat("#.00");
       System.out.println(fmt1.format(d1) + " " + fmt2.format(d1));
       System.out.println(fmt1.format(d2) + " " + fmt2.format(d2));
       System.out.println(fmt1.format(d3) + " " + fmt2.format(d3));
   }
}
