title: Convert .5 into 1/2
body: <p>I want to convert any number which ends in .5 so that it displays as the number followed by &frac12;, but I don't want 0.5 to display as 0&frac12; so I did it like this:</p>
  
  <pre><code>$used = str_replace("0.5", "&amp;frac12;", $used);
  $used = str_replace(".5", "&amp;frac12;", $used);
  </code></pre>
  
  <p>However I've now realised that this also converts 20.5 into 2&frac12; instead of 20&frac12;.</p>
  
  <p>I'm sure there's a better way of doing it but I don't know how.</p>
  
  <p><strong>Examples:</strong></p>
  
  <pre><code>5 returns "5"
  5.5 returns "5&amp;frac12;"
  0.5 returns "&amp;frac12;"
  10.5 returns "10&amp;frac12;"
  </code></pre>
  
  <p>I don't believe this is a duplicate of an existing question because that code is to replace or return "1/2" rather than "&frac12;"</p>