How to parse number in JSP?

The <fmt:parseNumber> tag is used to parse numbers, percentages, and currencies.


The <fmt:parseNumber> tag has the following attributes −

ValueNumeric value to read (parse)NoBody
parseLocaleLocale to use when parsing the numberNoDefault locale
integerOnlyWhether to parse to an integer (true) or floating-point number (false)Nofalse
patternCustom parsing patternNoNone
timeZoneTime zone of the displayed dateNoDefault time zone
varName of the variable to store the parsed numberNoPrint to page
scopeScope of the variable to store the formatted numberNopage

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.


<%@ taglib prefix = "c" uri = "" %>
<%@ taglib prefix = "fmt" uri = "" %>
      <title>JSTL fmt:parseNumber Tag</title>
      <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>

The above code will generate the following result −

Number Parsing:
Parsed Number (1) : 1250003.35
Parsed Number (2) : 1250003
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know