Returns a number forced to 2 decimal places.

/ Published in: PHP
Save to your folder(s)

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.

Copy this code and paste it in your HTML
  1. <?php
  2. printf('%02.2f', $number);
  3. ?>

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.