简体   繁体   English

强制FreeMarker始终使用小数点打印BigDecimal值

[英]Forcing FreeMarker to always print BigDecimal value with decimal point

In a Spring MVC application using FreeMarker for rendering views, how do I force FreeMarker to always print BigDecimal values with decimal points? 在使用FreeMarker渲染视图的Spring MVC应用程序中,如何强制FreeMarker始终使用小数点打印BigDecimal值?

For instance: 例如:

1000.12 -> 1000.12
1000    -> 1000.00

I tried 我试过了

${value?string("0.##")}

This printed 1000.12 correctly as 1000.12 but 1000 still printed as 1000 instead of 1000.00. 这打印1000.12正确为1000.12但1000仍然打印为1000而不是1000.00。

Have you tried ${1000?string("0.00")} ? 你试过${1000?string("0.00")}

If you need to round your numbers down use ((n * 100)?floor) / 100.0 expression 如果您需要将数字向下舍入使用((n * 100)?floor) / 100.0表达式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM