How can I format a number in PHP to display two decimal places?

To format a number in PHP to display two decimal places, you can use the number_format() function. This function allows you to specify the number of decimal places you want to display for a given number. By using number_format() with the appropriate parameters, you can easily format a number to display two decimal places.

$number = 123.456789;
$formatted_number = number_format($number, 2);
echo $formatted_number; // Output: 123.46