我对 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>
这就是输出:
Currency in USA $40.52
Currency in Germany $40.52
有什么问题吗?
谢谢你的帮助。
最佳答案
太棒了,我偶然得到了解决问题的方法:
诀窍是设置 setLocale
的范围参数标记到 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"/>
好的,我真的不知道它为什么起作用,但这里有一些关于我的项目设置的更多信息:
希望能帮助到你。
关于spring-mvc - SetLocale 无法在 jsp 站点中使用德语格式化货币,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10820068/