- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Display a currency value in Java
To display a currency in Java, use the following DecimalFormat −
DecimalFormat decFormat = new DecimalFormat("\u00a4#,##0.00");
Since, we have used the DecimalFormat class, therefore do not forget to import the following package −
import java.text.DecimalFormat;
Now, let us learn how to display percentage −
decFormat.format(877.80) decFormat.format(8.19) decFormat.format(9897.88)
The above will be displayed as −
$877.80 $8.19 $9,897.88
The following is the complete example −
Example
import java.text.DecimalFormat; public class Demo { public static void main(String[] argv) throws Exception { // for currency DecimalFormat decFormat = new DecimalFormat("\u00a4#,##0.00"); System.out.println(decFormat.format(877.80)); System.out.println(decFormat.format(8.19)); System.out.println(decFormat.format(9897.88)); System.out.println(decFormat.format(9.9099)); System.out.println(decFormat.format(12.788)); System.out.println(decFormat.format(9.678)); } }
Output
$877.80 $8.19 $9,897.88 $9.91 $12.79 $9.68
- Related Articles
- Display USD currency records with the correct format in MySQL
- Format currency with Java MessageFormat
- How to display a value when select a JList item in Java?
- Display a percentage in Java
- Display three letter-month value with SimpleDateFormat('MMM') in Java
- Display the minimum and maximum value of primitive data types in Java
- How to display a large component within a smaller display area in Java?
- How to Create a Currency Converter in JavaScript?
- How to display a JRadioButtonMenuItem in Java?
- What is the difference between floating currency and fixed currency?
- Add currency symbols in Excel
- Display a TreeSet in reverse order in Java
- Differentiate between floating currency exchange rate and fixed currency exchange rate
- How to display Absolute value of a number in C#?
- Display in console if Select list value contains a value from an array in JavaScript?

Advertisements