What are some best practices for handling numerical values in PHP to ensure correct formatting?

When handling numerical values in PHP, it is important to ensure that the values are correctly formatted to avoid any unexpected results or errors. One best practice is to use number_format() function to format numerical values with specified decimal points, thousands separator, and decimal separator.

// Example of formatting a numerical value with two decimal points and a comma as a thousands separator
$number = 123456.789;
$formatted_number = number_format($number, 2, '.', ',');
echo $formatted_number; // Output: 123,456.79