This example code shows the use of DecimalFormat class to format any number according to the locale.

 import java.text.DecimalFormat;
import java.util.Locale;

public class FrmtrExp {

    public static void main(String[] args) {

        DecimalFormat nf = (DecimalFormat) DecimalFormat
                .getInstance(Locale.GERMAN);

        System.out.println(nf.format(12345.45));
    }
}