Casting int to float in thymeleaf frontend

僤鯓⒐⒋嵵緔 提交于 2019-12-11 06:16:45

问题


I have something like this:

<span th:text="*{a / (b + c)}"></span>

where a, b and c are integers. I need the result to be a floating point number.

Any ideas?

Actual code:

<span th:text="(*{item.candidates } > 0 and *{item.budgetSeats + item.taxSeats} > 0)?*{#numbers.formatDecimal(item.candidates / (item.budgetSeats + item.taxSeats),1,2, 'POINT')}:'N/A'">

回答1:


The answer is simple:

Multiply (at least) one of the numbers with a float e.g. 1.0.

<span th:text="*{ (a * 1.0) / (b + c)}"></span> 


来源:https://stackoverflow.com/questions/39350392/casting-int-to-float-in-thymeleaf-frontend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!