Posted By

xtheonex on 01/27/09



Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Returns a number forced to 2 decimal places.

 / Published in: PHP

I use this snippet to force a number to 2 decimal places. Eg, For prices, PHP rounds the number 22.20 to 22.2. This code forces a zero on the end if there isn't 2 decimal places already.

  1. <?php
  2. printf('%02.2f', $number);
  3. ?>

Report this snippet  

You need to login to post a comment.