tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rashmi <>
Subject Getting integer portion of ceiling of a double number using fmt tags
Date Thu, 12 Feb 2009 18:17:37 GMT
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
      NumberFormat nf = NumberFormat.getIntegerInstance();

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

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.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message