
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to format currencies in JSP?
The <fmt:formatNumber> tag is used to format numbers, percentages, and currencies.
Attribute
The <fmt:formatNumber> tag has the following attributes −
Attribute | Description | Required | Default |
---|---|---|---|
Value | Numeric value to display | Yes | None |
type | NUMBER, CURRENCY, or PERCENT | No | Number |
pattern | Specify a custom formatting pattern for the output. | No | None |
currencyCode | Currency code (for type = "currency") | No | From the default locale |
currencySymbol | Currency symbol (for type = "currency") | No | From the default locale |
groupingUsed | Whether to group numbers (TRUE or FALSE) | No | true |
maxIntegerDigits | Maximum number of integer digits to print | No | None |
minIntegerDigits | Minimum number of integer digits to print | No | None |
maxFractionDigits | Maximum number of fractional digits to print | No | None |
minFractionDigits | Minimum number of fractional digits to print | No | None |
var | Name of the variable to store the formatted number | No | Print to page |
scope | Scope of the variable to store the formatted number | No | page |
Example
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <title>JSTL fmt:formatNumber Tag</title> </head> <body> <h3>Number Format:</h3> <c:set var = "balance" value = "120000.2309" /> <p>Currency in USA : <fmt:setLocale value = "en_US"/> <fmt:formatNumber value = "${balance}" type = "currency"/> </p> </body> </html>
The above code will generate the following result −
Number Format: Currency in USA : $120,000.23
- Related Questions & Answers
- How to parse currencies in JSP?
- How to format number in JSP?
- How to format percentages in JSP?
- How to format date in JSP?
- How to print date and time in specific format using JSP?
- What are the popular Crypto Currencies in circulation?
- How to parse number in JSP?
- How to parse percentages in JSP?
- How to parse date in JSP?
- What is the best datatype for currencies in MySQL?
- How to format Java LocalDateTime as ISO_DATE_TIME format
- How to parse an XML in JSP?
- How to delete Session data in JSP?
- How to use a filter in JSP?
- How to use resource bundle in JSP?
Advertisements