What are some best practices for handling decimal formatting in PHP?

When handling decimal formatting in PHP, it is important to ensure that numbers are displayed in the desired format with the correct number of decimal places. One common best practice is to use the number_format() function, which allows you to specify the number of decimal places to display. Additionally, it is recommended to use the round() function to round numbers to the desired precision before formatting them.

// Example of formatting a decimal number with 2 decimal places
$number = 123.456789;
$formatted_number = number_format(round($number, 2), 2);
echo $formatted_number; // Output: 123.46