What is the best practice for formatting numbers in PHP?

When formatting numbers in PHP, it is best practice to use the number_format() function. This function allows you to format a number with grouped thousands and decimal points. It takes the number you want to format as the first parameter and optional parameters for the number of decimal places, the decimal point character, and the thousands separator.

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