When using toString()
, Double adds commas (5143 is printed as 5,143).
How to disable the commas?
I use this method to format a double to string with a fixed locale, no grouping and with a minimum and maximum of fraction digits
public String formatNumber(double number){
NumberFormat nf = NumberFormat.getInstance(new Locale("en", "EN"));
nf.setMaximumFractionDigits(3);
nf.setMinimumFractionDigits(1);
nf.setGroupingUsed(false);
String str = nf.format(number);
return str;
}
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