What best practices should be followed when using number_format() function in PHP to avoid unexpected results?

When using the number_format() function in PHP, it is important to ensure that the input number is a valid numeric value. This can be done by using is_numeric() function to check if the input is a valid number before applying number_format(). Additionally, it is crucial to specify the correct number of decimal places and thousands separator to avoid unexpected results.

$number = 1234.5678;

if(is_numeric($number)){
    $formatted_number = number_format($number, 2, '.', ',');
    echo $formatted_number;
} else {
    echo "Invalid input number";
}