0

I am trying to show the number minus 20%. The number is in a map and I am not ale to get the value from there.

This is not working:

 <div class="row p-3 ml-1" th:each="r : ${roomTypes}">
  <div th:with="price=*{r.value}"  th:text="${#numbers.formatDecimal({price} * 0.8)}">x</div>

This is also not working

  <div th:text="${#numbers.formatDecimal({r.value} * 0.8)}">x</div>

Is there a way to get this value in Thymeleaf? Or another way I can make this calculation?

clickbait
  • 2,818
  • 1
  • 25
  • 61
sjs
  • 35
  • 1
  • 6

1 Answers1

1

The #numbers utility object doesn't have a method formatDecimal(number). Did you mean formatDecimal(number, minIntegerDigits, decimalDigits)?

In the expression th:with="price=*{r.value}" -- when you use *{r.value}, the asterisk specifies that you are working on a selected object (defined with th:object), but I don't see a th:object. In this case, you should just be using a regular ${...} expression.

Finally, your th:text expression th:text="${#numbers.formatDecimal({price} * 0.8)}" isn't valid syntax. In general, you shouldn't be nesting curly brackets { and }.

The corrected Thymeleaf should look something like:

<div class="row p-3 ml-1" th:each="r : ${roomTypes}">
  <div th:with="price=${r.value}"  th:text="${#numbers.formatDecimal(price * 0.8, 1, 2)}">x</div>
</div>
Metroids
  • 18,999
  • 4
  • 41
  • 52