Java Data Type How to - Format a number using the current Locale()








Question

We would like to know how to format a number using the current Locale().

Answer

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

public class Main {
  public static void main(String[] args) throws Exception {
   System.out.println(NumberFormat.getInstance(new Locale("us")).format(12345.12345)); 

  }
}

The code above generates the following result.