I need to make "12 345" from "12345", that is, to bring the numbers into a normal form. As far as I understood, NumberFormat deals with NumberFormat . How to do it?

    2 answers 2

    To the answer above, you can add a more accurate implementation of the NumberFormat:

     int num = 12345; String str = NumberFormat .getNumberInstance(Locale.US) .format(num) .replace(",", " "); 

    12 345

      String.format ()

       int num = 12345; String str = String.format("% d", num); 

      12 345

      NumberFormat

       int num = 12345; String str = NumberFormat.getNumberInstance(Locale.US).format(num)); 

      12,345

      DecimalFormat

       int num = 12345; DecimalFormat myFormatter = new DecimalFormat("# ###"); String str = myFormatter.format(num); 

      12 345