Convert any number to two digits number (with two decimal places), with PHP

Posted by nikola, With 0 Comments, Category: PHP,

Always important.

Let's say that you need to convert single number, to number with two decimal places. Primary number you want to convert can be with or without decimal places, integer, decimal, or even string type.

$number = 1205;
echo number_format((float)$number, 2, '.', '');

This will return a string.

Output will be:
1205.00

Leave a Reply

Your email address will not be published. Required fields are marked *