Rashmi
16 years ago
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
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