- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
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 €
Advertisements
To Continue Learning Please Login
Login with Google