代码之家  ›  专栏  ›  技术社区  ›  riddle_me_this He Drunh

删除货币的尾随零

  •  0
  • riddle_me_this He Drunh  · 技术社区  · 6 年前

    例如:

    49.00美元-->49美元

    我想象的是: #numbers.formatCurrency(abc.value, removeTrailingZeros)

    2 回复  |  直到 6 年前
        1
  •  5
  •   Metroids    6 年前

    $<span th:text="${#numbers.formatDecimal(value, 0, T(Math).round(value) == value ? 0 : 2)}" />
    

    (我可能更喜欢为此添加getter,或者某种实用方法。)

    如果你仍然只想使用 formatCurrency :

    ${#strings.replace(#numbers.formatCurrency(abc.value), '.00', '')}
    
        2
  •  0
  •   Xaltotun    6 年前

    在这种复杂的格式中,当您想在某些情况下保留零,在另一些情况下删除它们并显示$$而不是$-也许让您的自定义格式化程序bean并调用如下方法是有意义的

    ${@myFormatterBean.customFormat(abc.value)}
    

    您将能够控制所有格式。