What are the potential pitfalls of using number_format in PHP?

One potential pitfall of using number_format in PHP is that it may not handle certain edge cases correctly, such as rounding errors or unexpected input formats. To mitigate this, it is important to carefully validate the input data before applying number_format and handle any potential errors gracefully.

// Validate input data before using number_format
$number = 1234.5678;

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