Formatting doubles to two decimal places in Java produces a comma instead of a dot

I have read many threads, and it seems to be the best solution to keep 2 places in my double number:

DecimalFormat df = new DecimalFormat("#.00");
double d = 1.234567;
System.out.println(df.format(d));

But when I use it, it prints:

1,23

I want to keep the DOT, cause I need this format (#.##) to use (I will use it as string). How do I keep this dot?

Jon Skeet
people
quotationmark

If you want a dot rather than a comma, you should specify a Locale which uses dot as the decimal separator, e.g.

DecimalFormat df = new DecimalFormat("#.00",
                                    DecimalFormatSymbols.getInstance(Locale.US));

Basically, "." in a format pattern doesn't mean "dot", it means "decimal separator".

people

See more on this question at Stackoverflow