Add to Favorites

PHP number formatting

Number formatting in php can be done in a few ways. You can simply round your number ( 2 decimal place accuracy ):

 
$num = round($num,2);
 

You can simply remove all decimals and make it an integer:

 
$num = intval($num);
 

There is even a function in php to format numbers for display:

 
echo number_format($num,2,'.',',');
 

Comments

Be the first to leave a comment on this post.

Leave a comment

To leave a comment, please log in / sign up