Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to print a Double without commas

When using toString(), Double adds commas (5143 is printed as 5,143). How to disable the commas?

like image 883
Erik Sapir Avatar asked Feb 11 '10 07:02

Erik Sapir


1 Answers

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;       
 }
like image 57
Marco Avatar answered Oct 05 '22 23:10

Marco