In JSTL,
<fmt:formatNumber value="${1.6}" type="number" pattern="#"/>
returns 2
and the following
<fmt:formatNumber value="${1.4}" type="number" pattern="#"/>
returns1
and I need 2
, a ceiling of a number.
Is there a direct way to achieve this in JSTL (or the only way to do so is by using an appropriate custom tag)?
A primary feature of JSTL is its support for an expression language (EL). An expression language, in concert with JSTL tags, makes it possible to easily access application data and manipulate it in simple ways without having to use scriptlets or request-time expressions.
JSTL - fn:length() Function The fn:length() function returns the string length or the number of items in a collection.
The <c:out> tag is similar to JSP expression tag, but it can only be used with expression. It will display the result of an expression, similar to the way < %=... % > work.
JSTL Core Tags c:set allows to set the result of an expression in a variable within a given scope. Using this tag helps to set the property of 'JavaBean' and the values of the 'java. util. Map' object.
The default rounding mode of DecimalFormat
that is used by <fmt:formatNumber>
is RoundingMode.HALF_EVEN
. There is no way to change that via any tag attribute. Just add 0.5
to the value when it's not an odd integer to make it to behave like RoundingMode.CEILING
.
<fmt:formatNumber value="${bean.number + (bean.number % 1 == 0 ? 0 : 0.5)}"
type="number" pattern="#" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With