You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Rashmi <ra...@gmail.com> on 2009/02/12 19:17:37 UTC
Getting integer portion of ceiling of a double number using fmt tags
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.
-Rashmi
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
Re: Getting integer portion of ceiling of a double number using fmt
tags
Posted by Rashmi <ra...@gmail.com>.
I've submitted a feature request to jstl-spec-public to add
roundingMode attribute to fmt:formatNumber and fmt:parseNaumber .
-Rashmi
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org