今天在项目中发现从界面使用freemarker取值进行计算的时候,会自动把小数点给忽略掉,在网上找到了解决方案。
在开发中很容易忽视一点,输入一个值(可能是小数),输出时如果不做处理,就很容易出现
隐形的BUG。比如,如果从数据库取出一个0.22的数值,一般的输出${x?if_exists?html},
这时是显示0,而不是0.22。
应该写成${x?if_exists?string.number} 或者 ${x?if_exists.toString()?html}
下面就是关于数字的具体介绍:
Built-ins for numbers
Related FAQs: Do you have things like 1,000,000 or 1 000 000 instead of 1000000, or something like 3.14 instead of 3,14 or vice versa? See this and this FAQ entry, also note the c built-in above.
c
Note
This built-in exists since FreeMarker 2.3.3.
This built-in converts a number to string for ``computer audience'' as opposed to human audience. That is, it formats with the rules that programming languages used to use, which is independent of all the locale and number format settings of FreeMarker. It always uses dot as decimal separator, and it never uses grouping separators (like 3,000,000), nor exponential form (like 5E20), nor superfluous leading or trailing 0-s (like