title: In PHP, how to print a number with 2 decimals, but only if there are decimals already?
body: <p>I have a basic index.php page with some variables that I want to print in several places - here are the variables:</p>
  
  <pre><code>&lt;?php
    $firstprice = 1.50;
    $secondprice = 3.50;
    $thirdprice = 20;
  ?&gt;
  </code></pre>
  
  <p>My challenge is that later in the document, when I print, I get the prices without the second '0' in the price - this is what happens:</p>
  
  <pre><code>&lt;?php print "$firstprice";?&gt; // returns 1.5 - not 1.50!
  </code></pre>
  
  <p>SO - I know how to do this with JS, but how is this done in PHP 5+?  Basically I want to print the second '0' if there is already a decimal, so if the variable is equal to '3', it stays as '3', but if it's equal to '3.5' it converts to display '3.50' with a second '0', etc.</p>
  
  <p>Here's a JS example - what's the PHP equivalent?</p>
  
  <p>JS:</p>
  
  <pre><code>.toFixed(2).replace(/[.,]00$/, ""))
  </code></pre>
  
  <p>Many thanks!!</p>