Wednesday, June 27, 2018

Convert Number to String with Locale (Comma separated String)



import java.io.*;
import java.text.NumberFormat;
import java.util.Locale;

class MyCode {
  public static void main (String[] args) {
    int number = 1234567;
      NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
      String numberAsString = numberFormat.format(number);
      System.out.println(numberAsString);
  }
}

No comments: