如何在JSP中格式化百分比?
<fmt:formatNumber> 标签用于格式化数字、百分比和货币。
属性
<fmt:formatNumber> 标签具有以下属性:
| 属性 | 描述 | 必填 | 默认值 |
|---|---|---|---|
| 值 | 要显示的数值 | 是 | 无 |
| type | NUMBER、CURRENCY 或 PERCENT | 否 | Number |
| pattern | 指定输出的自定义格式模式。 | 否 | 无 |
| currencyCode | 货币代码(对于 type = "currency") | 否 | 来自默认区域设置 |
| currencySymbol | 货币符号(对于 type = "currency") | 否 | 来自默认区域设置 |
| groupingUsed | 是否对数字进行分组 (TRUE 或 FALSE) | 否 | true |
| maxIntegerDigits | 要打印的整数位数的最大值 | 否 | 无 |
| minIntegerDigits | 要打印的整数位数的最小值 | 否 | 无 |
| maxFractionDigits | 要打印的小数位数的最大值 | 否 | 无 |
| minFractionDigits | 要打印的小数位数的最小值 | 否 | 无 |
| var | 用于存储格式化数字的变量名称 | 否 | 打印到页面 |
| scope | 用于存储格式化数字的变量的作用域 | 否 | page |
示例
<%@ 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%
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP