con*_*nce 7 jstl jsp-tags spring-mvc currency-formatting
我对jstl标签库感到困惑:
我想将数字格式化为具有德国风格的货币...但我尝试过的所有内容都没有...
我找到了以下示例,但输出是相同的 - .-
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core"
prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt"
prefix="fmt" %>
<html>
<head>
<title>format number</title>
</head>
<body>
<c:set var="val" value="40.52" />
<p> Currency in USA
<fmt:setLocale value="en_US"/>
<fmt:formatNumber value="${val}"
type="currency" />
</p>
<p>Currency in Germany
<fmt:setLocale value="de_DE"/>
<fmt:formatNumber value="${val}"
type="currency"/>
</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这就是输出:
Currency in USA $40.52
Currency in Germany $40.52
Run Code Online (Sandbox Code Playgroud)
那里出了什么问题?
谢谢你的帮助.
con*_*nce 16
太棒了,我偶然得到了解决问题的方法:
诀窍是将setLocale标签的scope-parameter设置为session:D然后它工作^^甜蜜:)
所以正确的代码片段如下所示:
<c:set var="val" value="40.52" />
<p> Currency in USA
<fmt:setLocale value="en_US" scope="session"/>
<fmt:formatNumber value="${val}"
type="currency" />
</p>
<p>Currency in Germany
<fmt:setLocale value="de_DE" scope="session"/>
<fmt:formatNumber value="${val}"
type="currency"/>
Run Code Online (Sandbox Code Playgroud)
好的,我真的不知道它为什么会起作用,但这里有一些关于我的项目设置的更多信息:
希望能帮助到你.
| 归档时间: |
|
| 查看次数: |
5003 次 |
| 最近记录: |