`<fmt:parseNumber>` Tag

JSP 标准标签库JSP Standard Tag Library

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

Syntax Format

<fmt:parseNumber
  value="<string>"
  type="<string>"
  pattern="<string>"
  parseLocale="<string>"
  integerOnly="<string>"
  var="<string>"
  scope="<string>"/>

Attributes

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

Attribute Description Required Default Value
value The number to be parsed no Body
type NUMBER, CURRENCY, or PERCENT no number
parseLocale The locale used when parsing the number no Default locale
integerOnly Whether to parse only integers (true) or floating-point numbers (false) no false
pattern Custom parsing pattern no None
timeZone Time zone of the date to be displayed no Default time zone
var Variable to store the parsed number no Print to page
scope Scope of the var attribute no page

The pattern attribute has the same function as the pattern in the `<fmt:formatNumber>` tag. When parsing, the pattern attribute tells the parser the expected format.



Example Demonstration

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ 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 标签</title>
</head>
<body>
<h3>数字解析:</h3>
<c:set var="balance" value="1250003.350" />

<fmt:parseNumber var="i" type="number" value="${balance}" />
<p>数字解析 (1) : <c:out value="${i}" /></p>
<fmt:parseNumber var="i" integerOnly="true" 
                       type="number" value="${balance}" />
<p>数字解析 (2) : <c:out value="${i}" /></p>

</body>
</html>

The running result is as follows:

数字解析:

数字解析 (1) : 1250003.35

数字解析 (2) : 1250003

JSP 标准标签库JSP Standard Tag Library

Other extensions