- 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.getPercentageInstance() method
The java.text.NumberFormat class is used for formatting numbers and currencies as per a specific Locale. Number formats varies from country to country
To format a number as percentage you need a percentage NumberFormat instance. To achieved this, use the getPercentageInstance() method.
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.getPercentInstance(Locale.FRANCE); // points double points = 1.78; double totalPoints = points * 1000; System.out.println(n.format(points)); System.out.println(n.format(totalPoints)); } }
Output
178 % 178 000 %
Advertisements
To Continue Learning Please Login
Login with Google