What is the purpose of using number_format in PHP and how does it work?

The purpose of using number_format in PHP is to format a number with grouped thousands and decimal points. This function can be used to make large numbers more readable by adding commas as thousands separators and specifying the number of decimal places.

// Example of using number_format to format a number
$number = 1234567.89;
$formatted_number = number_format($number, 2); // Outputs: 1,234,567.89

echo $formatted_number;