带有JSTL的格式编号,不四舍五入 [英] Format number with JSTL and no rounding

查看:117
本文介绍了带有JSTL的格式编号,不四舍五入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用<fmt:formatNumber/> jstl标签格式化数字.输出应限制在小数点后3位,但不允许四舍五入,因此使用属性maxFractionDigits="3"不合适,因为会四舍五入该数字.

I need to format number using <fmt:formatNumber/> jstl tag. The output should be restricted to 3 places after the decimal point, but rounding isn't allowed, so using the attribute maxFractionDigits="3" isn't appropriate, cause it rounds the number.

您有什么建议吗?

推荐答案

您可以在格式化之前从数字中减去0.0005.这样一来,四舍五入就相当于将原始数字舍入到小数点后三位.

You could subtract 0.0005 from the number before formatting it. That way the rounding will be equivalent to truncating the original number to 3 decimal places.

<fmt:formatNumber value="${myNumber - 0.0005}" maxFractionDigits="3"/>

这篇关于带有JSTL的格式编号,不四舍五入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆