The representation of the numbers differ from one locale to another. Internationalizing the numbers is good approach for the application that displays the informations according to the locales.
The NumberFormat class is used to format the number according to the specific locale. To get the instance of the NumberFormat class, we need to call either getInstance() or getNumberInstance() methods.
Syntax of these methods is given below:
public static NumberFormat getNumberInstance(Locale locale) public static NumberFormat getInstance(Locale locale)//same as above
In this example, we are internationalizing the number. The format method of the NumberFormat class formats the double value into the locale specific number.
import java.text.NumberFormat; import java.util.*; public class InternalizationNumber { static void printNumber(Locale locale){ double dbl=105000.3245; NumberFormat formatter=NumberFormat.getNumberInstance(locale); String number=formatter.format(dbl); System.out.println(number+" for the locale "+locale); } public static void main(String[] args) { printNumber(Locale.UK); printNumber(Locale.US); printNumber(Locale.FRANCE); printNumber(Locale.JAPAN); } }