jstl数据类型转化问题

备份

Hello all,

I'm trying to get the integer portion of the ceiling of a number using
JSTL 1.2 fmt tags on Tomcat 6.x, JavaSE 6.x.

So, if my number is 1.2 , the result expected is 2 (no fractions) or
if my number is 1.6 the result wanted is 2

In JavaSE 6 this can be accomplished with NumberFormat
http://java.sun.com/javase/6/docs/api/java/text/NumberFormat.html
NumberFormat nf = NumberFormat.getIntegerInstance();
nf.setRoundingMode(RoundingMode.CEILING);
nf.isParseIntegerOnly();
out.println(nf.format(1.2d));

Math.ceil(1.2d) gives 2.0

I tried the following with JSTL fmt tags,

<fmt:formatNumber value="${1.2}" type="number" pattern="#"/> gives 1
<fmt:formatNumber value="${1.6}" type="number" pattern="#"/> gives 2

<fmt:parseNumber value="${1.2}" type="number" integerOnly="true"/> gives 1
<fmt:parseNumber value="${1.6}" type="number" integerOnly="true"/> gives 1

The fmt:formatNumber or fmt:parsNumber do not have a roundingMode
attribute http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/fmt/formatNumber.html
,

This gives:
<c:set var="mynum"><%=Math.ceil(1.2d)%></c:set>
<fmt:formatNumber value="${mynum}" type="number" pattern="#"/>
the expected result 2 .

Or the ceiling (and other rounding modes) could be accomplished with a
custom tag.

I wish the fmt:formatNumber and fmt:parseNumber provide the
roundingMode attribute.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值