Monday, 3 February 2020

PHP convert a string to two decimal places

$foo = "105";
echo number_format((float)$foo, 2, '.', '');  // Outputs -> 105.00
number_format formats a number, in this case format a float to two decimal places, 
number_format returns a number
https://stackoverflow.com/questions/4483540/show-a-number-to-two-decimal-places

No comments:

Post a comment