Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Format Numbers with commas

I just want the numbers to be output in "well readable" format. e.g. you can output 100000 as 100.000 which would be more readable.

Is there an already existing method that can be used for this?

like image 600
forty4seven Avatar asked Nov 01 '25 11:11

forty4seven


1 Answers

You can use NumberFormat:

int n = 100000;
String formatted = NumberFormat.getInstance().format(n);
System.out.println(formatted);

Output:

100,000
like image 141
Majed Badawi Avatar answered Nov 04 '25 02:11

Majed Badawi