// 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;
import java.text.MessageFormat;
import java.text.NumberFormat;

public class NumFmt {
    public static void main(String[] args) {
        double x = 123.456;
        System.out.println(x);
        System.out.printf("%f\n", x);
        System.out.printf("%.4f\n", x);
        System.out.println(String.format("%f", x));
        System.out.println(String.format("%.4f", x));
        NumberFormat nf = new DecimalFormat(".0000");
        System.out.println(nf.format(x));
        System.out.println(MessageFormat.format("{0,number,.0000}", x));
    }
}
