可以使用JSTL fmt:formatNumber来获得以下输出:"1 234.56"吗? [英] Can JSTL fmt:formatNumber be used to get this output: "1 234.56"?

查看:68
本文介绍了可以使用JSTL fmt:formatNumber来获得以下输出:"1 234.56"吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以这种特定格式格式化数字:

I'm trying to get numbers formatted in this specific format:

"1 234.56"

"1 234.56"

因此,两个小数点之间用一个点分隔.并用空格字符(可选的单引号)将数千个分组.输入值将永远不会大于9999.99.

So, two decimals, separated by a dot. And grouping thousands with a space char (optionally a single quote). The input values will never be larger than 9999.99.

为此,我尝试使用模式,甚至在语言环境中玩耍,但无济于事.

I tried using patterns fo this, and even playing around with locales, but to no avail.

推荐答案

这是一种方法.

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="val" value="9999.99" /> 
<fmt:formatNumber value="${val}" pattern="#,###.##" var="pat" /> 
${fn:replace(pat, ",", " ")}

这篇关于可以使用JSTL fmt:formatNumber来获得以下输出:"1 234.56"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆