如何在JSP中格式化百分比?
<FMT:formatNumber>标记用于格式数字,百分比,和货币。
属性
<FMT:formatNumber>标签具有以下属性-
示例
<%@ 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>Formatted Number (1): <fmt:formatNumber type = "percent" maxIntegerDigits="3" value = "${balance}" /></p> <p>Formatted Number (2): <fmt:formatNumber type = "percent" minFractionDigits = "10" value = "${balance}" /></p> <p>Formatted Number (3): <fmt:formatNumber type = "percent" maxIntegerDigits = "3" value = "${balance}" /></p> </body> </html>
上面的代码将产生以下结果-
Number Format: Formatted Number (1): 023% Formatted Number (2): 12,000,023.0900000000% Formatted Number (3): 023%