Ceiling of a number in JSTL/EL

…衆ロ難τιáo~ 提交于 2019-11-28 08:22:19
BalusC

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="#" />

Try this code:

<fmt:formatNumber value="${N+(1-(N%1))%1}" type="number" pattern="#"/>

where N is the name of your variable.

Regards

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!