title: Always display specified number of decimal places in Excel
body: <p>I need to display two decimal places in Excel (xlsx). I'm using <a href="http://phpexcel.codeplex.com/downloads/get/212184" rel="noreferrer"><code>PHPExcel</code></a>. In PHP, I can use something like the following to display only the specified number of decimal paces.</p>
  
  <pre><code>echo sprintf("%0.2f", $row['price']);
  </code></pre>
  
  <p>which always displays two decimal places even though the value contains no decimal point i.e if the value of <code>$row['price']</code> is <code>1500</code>, it will echo <code>1500.00</code>. I need to write the same value to excel. I tried </p>
  
  <pre><code>$sheet-&gt;setCellValue("A1", sprintf("%0.2f", $row['price']));
  </code></pre>
  
  <p>but it displays <code>1500</code> instead of displaying <code>1500.00</code> (because Excel automatically assumes it to be a numeric value and the part after the decimal point i.e <code>.00</code> in this case is truncated). </p>
  
  <p>I also tried the following</p>
  
  <pre><code>$sheet-&gt;getStyle("A1")-&gt;getNumberFormat()-&gt;setFormatCode('0.00');
  </code></pre>
  
  <p>but it's not sufficient to achieve what is specified.</p>
  
  <p>How can I (always) display the specified number of decimal places in Excel using PHPExcel?</p>