Java NumberFormat.getCurrencyInstance() method



The getCurrencyInstance() method of the NumberFormat class returns the instance of the NumberFormat class. The java.text.NumberFormat class is used for formatting numbers and currencies as per a specific Locale. Number formats varies from country to country

Here, we have considered a locale.

NumberFormat n = NumberFormat.getCurrencyInstance(Locale.FRANCE);

Then, we have formatted a double value with the currency.

double points = 1.78; System.out.println(n.format(points));

The following is the final example.

Example

 Live Demo

import java.text.NumberFormat; import java.util.Locale; public class MainClass {     public static void main(String[] args) {        // Currency of France is Euro        NumberFormat n = NumberFormat.getCurrencyInstance(Locale.FRANCE);        // points        double points = 1.78;        double totalPoints = points * 1000;        System.out.println(n.format(points));        System.out.println(n.format(totalPoints));     } }

Output

1,78 € 1 780,00 €
Updated on: 2020-06-26T09:10:36+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements