Lets assume we have one million.
In English it should be formatted as 1,000,000
in German it should be 1.000.000
.
locale which is the locale value to be applied on the this method. format which is the format according to which the String is to be formatted. args which is the number of arguments for the formatted string. It can be optional, i.e. no arguments or any number of arguments according to the format.
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)
Using NumberFormat class:
For English:
NumberFormat nf_us = NumberFormat.getInstance(Locale.US);
String number_us = nf_us.format(1000000);
For German:
NumberFormat nf_ge = NumberFormat.getInstance(Locale.GERMAN);
String number_ge = nf_ge.format(1000000);
You can use NumberFormat.
Android documentation is quite clear on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With