如何在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