Java – How to set thousands separator in Java

bigdecimaljavanumber-formatting

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.

Best Answer

You can use format function with ",";

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

//str = 124,750

"," includes locale-specific grouping characters.

docs