Search code examples
mathjspjstlelrounding

How do I round a number in JSTL?


I'm doing a division in a JSP and I'd like to round the result - how should I do this?

i.e.

<c:set
  var="expiry"
  value="${(expire.time - now.time) / (60 * 1000)}"/>

...how do I round the result?

Thanks,


Solution

  • As an alternative:

    <fmt:formatNumber var="expiry"
      value="${(expire.time - now.time) / (60 * 1000)}"
      maxFractionDigits="0" />
    

    This way you do not lose localization (commas and dots).