Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Casting int to float in thymeleaf frontend

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'">
like image 984
Irikos Avatar asked Sep 14 '25 00:09

Irikos


1 Answers

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> 
like image 193
Irikos Avatar answered Sep 15 '25 13:09

Irikos