How can PHP be used to format numbers with a specific number of decimal places, including adding trailing zeros?

To format numbers with a specific number of decimal places in PHP, you can use the number_format() function. This function allows you to specify the number of decimal places you want, as well as how to handle trailing zeros. By setting the third parameter to 0, you can ensure that trailing zeros are added to the number if necessary.

$num = 123.456;
$formatted_num = number_format($num, 2, '.', ''); // Formats the number with 2 decimal places and no thousands separator
echo $formatted_num; // Output: 123.46