How can the number_format function in PHP be used effectively to display decimal values correctly?

When displaying decimal values in PHP, the number_format function can be used to format the number with commas as thousands separators and a specified number of decimal places. To display decimal values correctly, you can use the number_format function with the appropriate parameters to format the number as needed.

$number = 123456.789;
$formatted_number = number_format($number, 2); // Displays as 123,456.79
echo $formatted_number;