formatting - PHP: show a number to 2 decimal places -
what's correct way round php string 2 decimal places?
$number = "520"; // it's string db $formatted_number = round_to_2dp($number); echo $formatted_number; output "520.00";
how function round_to_2dp() definition should be?
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 returns string.
Comments
Post a Comment