How can the number_format() function be used to format the output of a calculation in PHP?

When performing a calculation in PHP that results in a numerical output, you can use the number_format() function to format the output with commas for thousands separators and a specified number of decimal places. This can make the output more readable and user-friendly.

$number = 1234567.89;
$formatted_number = number_format($number, 2); // Outputs: 1,234,567.89
echo $formatted_number;