Show a number to two decimal places

What’s the correct way to round a PHP string to two decimal places? $number = “520”; // It’s a string from a database $formatted_number = round_to_2dp($number); echo $formatted_number; The output should be 520.00; How should the round_to_2dp() function definition be? 25 s 25 You can use number_format(): return number_format((float)$number, 2, ‘.’, ”); Example: $foo = … Read more