How can the number_format function in PHP be used to correctly format decimal points?

When working with decimal numbers in PHP, it's important to format them correctly for display. The number_format function in PHP can be used to achieve this by specifying the number of decimal points to display and the thousands separator. This function takes the number to be formatted as the first parameter, the number of decimal points as the second parameter, the decimal point separator as the third parameter, and the thousands separator as the fourth parameter.

$number = 1234.56789;
$formatted_number = number_format($number, 2, '.', ',');
echo $formatted_number; // Output: 1,234.57