Home

Published

- 1 min read

java add commas to numbers

img of java add commas to numbers

The solution for this is noted below

java add commas to numbers

Solution

   String number = "1000500000.574";
double amount = Double.parseDouble(number);
DecimalFormat formatter = new DecimalFormat("#,###.00");
// the zeroes after the point are the number of digits shown after the period
// you can also switch point and commas and get for example 1.002,45
System.out.println(formatter.format(amount));
// this prints 1,000,500,000.57

Try other methods by searching on the site. That is if this doesn’t work