How can the number_format function in PHP be used effectively to format float variables?

The number_format function in PHP can be used effectively to format float variables by specifying the number of decimal places to round the number to and choosing a character for the decimal point and thousands separator. This function is useful for displaying numbers in a more readable format, such as adding commas for thousands separators.

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