如何使用 thymeleaf 格式化 HTML 中的数字字符串
How to format the number string in HTML with thymeleaf
如何使用 thymeleaf 将数字字符串格式化为 4 位格式。
例如。 5 - > 0005
使用数字格式格式化字符串。如下:
th:text="${#numbers.formatInteger(num,5)}"
我用的是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 位数字,那么这将添加两个前导零,如果长度超过最大大小,则不会有任何变化输出即与输入相同。
例如。 input: 12345678
然后 output: 0012345678
如何使用 thymeleaf 将数字字符串格式化为 4 位格式。 例如。 5 - > 0005
使用数字格式格式化字符串。如下:
th:text="${#numbers.formatInteger(num,5)}"
我用的是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 位数字,那么这将添加两个前导零,如果长度超过最大大小,则不会有任何变化输出即与输入相同。
例如。 input: 12345678
然后 output: 0012345678