- Trending Categories
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
How to parse number in JSP?
The <fmt:parseNumber> tag is used to parse numbers, percentages, and currencies.
Attribute
The <fmt:parseNumber> tag has the following attributes −
Attribute | Description | Required | Default |
---|---|---|---|
Value | Numeric value to read (parse) | No | Body |
type | NUMBER, CURRENCY, or PERCENT | No | number |
parseLocale | Locale to use when parsing the number | No | Default locale |
integerOnly | Whether to parse to an integer (true) or floating-point number (false) | No | false |
pattern | Custom parsing pattern | No | None |
timeZone | Time zone of the displayed date | No | Default time zone |
var | Name of the variable to store the parsed number | No | Print to page |
scope | Scope of the variable to store the formatted number | No | page |
A pattern attribute is provided that works just like the pattern attribute for the <fmt:formatNumber> tag. However, in the case of parsing, the pattern attribute tells the parser what format to expect.
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:parseNumber Tag</title> </head> <body> <h3>Number Parsing:</h3> <c:set var = "balance" value = "1250003.350" /> <fmt:parseNumber var = "i" type = "number" value = "${balance}" /> <p>Parsed Number (1) : <c:out value = "${i}" /></p> <fmt:parseNumber var = "i" integerOnly = "true" type = "number" value = "${balance}" /> <p>Parsed Number (2) : <c:out value = "${i}" /></p> </body> </html>
The above code will generate the following result −
Number Parsing: Parsed Number (1) : 1250003.35 Parsed Number (2) : 1250003
- Related Articles
- How to parse percentages in JSP?
- How to parse currencies in JSP?
- How to parse date in JSP?
- How to parse an XML in JSP?
- How to format number in JSP?
- Is there any JSTL library to parse XML in a JSP?
- Parse and format a number to octal in Java
- Parse and format a number to decimal in Java
- How to parse JSON in Java?
- How to parse date in MySQL?
- How to parse HTML in android?
- How to parse JSON object in JavaScript?
- How to parse json string in android?
- How to parse an URL in JavaScript?
- How to parse JSONArray in Android app?

Advertisements