Struts 2格式钱四舍五入

Struts 2 format money rounding off

我使用 <s:text name="format.money"> 标记来格式化 BigDecimal 值 4.74500000。

结果是 4.74 美元,但我预计是 4.75 美元。

为什么会这样? Struts 如何处理格式?因为当我格式化 57.625090 时,它显示是 $57.63 是正确的。

根据documentation, money.format uses DecimalFormat with a pattern of ##0.00 to format numbers. Namely, round to closest number with only two fractional digits, with ties being rounded to the even neighbor

这与您的结果一致。