How to set thousands separator in Java?

Funtime picture Funtime · Mar 16, 2011 · Viewed 168.3k times · Source

How to set thousands separator in Java?
I have String representation of a BigDecimal that I want to format with a thousands separator and return as String.

Answer

syloc picture syloc · Oct 2, 2012

You can use format function with ",";

int no = 124750;
String str = String.format("%,d", no);

//str = 124,750

"," includes locale-specific grouping characters.

docs