In How to control significant digits, ONLY when necessary, in a Thymeleaf template? they find a workaround for the case that it is an integer:
<span th:text="${user.averageScore} % 1 == 0? ${user.averageScore} :${#numbers.formatDecimal(user.averageScore, 0, 2)}"/>