Java Language NumberFormat NumberFormat

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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

    numberFormat.format(10000000.99);

  1. Format Currency

    NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(locale); currencyFormat.format(10340.999);

  1. Format Percentage

    NumberFormat percentageFormat = NumberFormat.getPercentInstance(locale); percentageFormat.format(10929.999);

  2. Control Number of Digits

numberFormat.setMinimumIntegerDigits(int digits)
numberFormat.setMaximumIntegerDigits(int digits)
numberFormat.setMinimumFractionDigits(int digits)
numberFormat.setMaximumFractionDigits(int digits)


Got any Java Language Question?