【问题标题】:How to format the number string in HTML with thymeleaf如何使用 thymeleaf 格式化 HTML 中的数字字符串
【发布时间】:2015-03-24 16:02:56
【问题描述】:

如何使用 thymeleaf 将数字字符串格式化为 4digit 格式。 例如。 5 - > 0005

【问题讨论】:

    标签: java html thymeleaf


    【解决方案1】:

    使用数字格式格式化字符串。如下:

    th:text="${#numbers.formatInteger(num,5)}"
    

    【讨论】:

    • 缺少右括号,我无法编辑,因为这是一个小改动
    【解决方案2】:

    我使用的是thymeleaf 3.0.9,指的是Thymeleaf format。 您可以通过两种方式做到这一点,

     <p th:text="${#numbers.formatInteger(AccountNo,10)}"> This text will replace by AccountNo</p>
    

    <p >Hi format [[${#numbers.formatInteger(AccountNo,10)}]] </p>
    

    10 是帐号的最大长度。

    如果您提供 8 位数字,那么这将添加两个前导零,如果长度超过最大大小,则输出不会发生变化,即与输入相同。 p>

    例如。 input: 12345678 然后output: 0012345678

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-17
      • 2021-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-17
      相关资源
      最近更新 更多