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?
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With