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,
In C#, Math. Round() is a Math class method which is used to round a value to the nearest integer or to the particular number of fractional digits.
In TypeScript, the floor() method of the Math object is the opposite of the ceil method. It used to round a number downwards to the nearest integer. It returns the largest integer less than or equal to a number.
Calculates the closest integer that is closest to the value of the parameter.
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).
I used:
${fn:substringBefore(expiry, '.')}
which truncates rather than rounding, but that may be good enough.
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