How can I format a String number to have commas in android Edit Field

Solution 1:

You could use DecimalFormat and just format the number

DecimalFormat formatter = new DecimalFormat("#,###,###");
String yourFormattedString = formatter.format(100000);

The result will be

  • 1,000,000 for 1000000
  • 10,000 for 10000
  • 1,000 for 1000

Update 12/02/2019

This String.format("%,d", number) would be a better(less hardcoded) solution as indicated in the comments below by @DreaminginCode so I thought I would add it here as an alternative

Solution 2:

try this one hope it will help.

 System.out.println(NumberFormat.getNumberInstance(Locale.US).format(1000));