Are there any best practices for formatting numbers in PHP to avoid incorrect output?

When formatting numbers in PHP, it's important to be aware of potential issues such as rounding errors or incorrect output due to different number formats. To avoid these problems, it's recommended to use number_format() function which formats a number with grouped thousands and decimal points. This function allows you to specify the number of decimal places and the decimal and thousands separators.

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