NumberFormat in Java

Java NumberFormat tutorial shows how to format numbers in Java.  Different countries have different number formats and considering this we can have different formats using Locale of java. Using locale can help in formatting

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

using above format you can perform various tasks

  1. Format Number
  1. Number Format Currency
NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(locale);
  1. Percentage Format
NumberFormat percentageFormat = NumberFormat.getPercentInstance(locale);
  1. Control Number of Digits
numberFormat.setMinimumIntegerDigits(int digits)
numberFormat.setMaximumIntegerDigits(int digits)
numberFormat.setMinimumFractionDigits(int digits)
numberFormat.setMaximumFractionDigits(int digits)

Leave a Comment