Recent Posts

Format a number with two decimal places in PHP

To accomplish this you can use number_format()

return number_format((float)$number, 2, '.', '');
Example:

$foo = "105";
echo number_format((float)$foo, 2, '.', '');  // Outputs -> 105.00
This function return a string

No comments:

Post a Comment