What is the role of number_format() in PHP and how can it affect numerical calculations?

The number_format() function in PHP is used to format numerical values with specified decimal points, thousands separators, and decimal separators. When using number_format() on numerical calculations, it can affect the accuracy of the results due to rounding errors. To ensure accurate calculations, it's recommended to apply number_format() only when displaying the final result to the user.

$number1 = 10.555;
$number2 = 20.123;

// Perform numerical calculation
$result = $number1 + $number2;

// Display the result with number_format()
echo number_format($result, 2);