NumberFormat

suggest change

Different countries use different number formats. A Locale selects one of those formats.

Locale locale = new Locale("en", "IN");
NumberFormat numberFormat = NumberFormat.getInstance(locale);

Using the formatter above, you can:

  1. Format Number

numberFormat.format(10000000.99);

  1. Format Currency
NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(locale);
currencyFormat.format(10340.999);
  1. Format Percentage
NumberFormat percentageFormat = NumberFormat.getPercentInstance(locale);
// 1 is 100%. This call formats 10929.999, not 10929.999%.
percentageFormat.format(10929.999);
  1. Control Number of Digits
numberFormat.setMinimumIntegerDigits(int digits)
numberFormat.setMaximumIntegerDigits(int digits)
numberFormat.setMinimumFractionDigits(int digits)
numberFormat.setMaximumFractionDigits(int digits)

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents