Java: Thousands Separator

Kelinci Kertas > Blog > Code > Java: Thousands Separator

Separate number into money format or separate by 3 digits including numbers behind comma.

String format = "###,###.##"; // for separate format
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
symbols.setGroupingSeparator(','); // the string that put between 3 digits

DecimalFormat formatter = new DecimalFormat("###,###.##", symbols);
System.out.println(formatter.format(number));

if need another format separator, just change with these codes

symbols.setGroupingSeparator('.');
symbols.setDecimalSeparator(',');

Leave a Reply

Your email address will not be published. Required fields are marked *