title: How to control significant digits, ONLY when necessary, in a Thymeleaf template?
body: <p>When using the <code>th:text</code> attribute to evaluate and render a numeric field, Thymeleaf displays the full number of digits available.  For example, this:</p>
  
  <pre><code>&lt;span th:text="${user.averageScore}"/&gt;
  </code></pre>
  
  <p>... might render on the browser screen:</p>
  
  <pre><code>107.54896
  </code></pre>
  
  <p>I would like to display this amount rounded to no more than two decimal places.  From the Thymeleaf documentation, this:</p>
  
  <pre><code>&lt;span th:text="${#numbers.formatDecimal(user.averageScore, 0, 2)}"/&gt;
  </code></pre>
  
  <p>... changes the output to this:</p>
  
  <pre><code>107.55
  </code></pre>
  
  <p>However, is there a way to make this more flexible... in cases where the value has FEWER than than two decimal places?  I only want to remove decimal places, to get down to two.  I never want to ADD decimal places, to get up to two.  If the field above has a value of 107, then it would render as:</p>
  
  <pre><code>107.00
  </code></pre>
  
  <p>How can I make Thymeleaf format numbers for two decimal places, or less... rather than just two decimal places, no matter what?</p>