How can you reduce a double variable to 2 decimal places in PHP when outputting it in a table?

When outputting a double variable in a table in PHP, you can reduce it to 2 decimal places by using the number_format() function. This function takes the double variable as the first parameter and the number of decimal places as the second parameter. It then returns the formatted number as a string with the specified number of decimal places.

<?php
$doubleVariable = 123.456789;
$formattedNumber = number_format($doubleVariable, 2);
echo "<td>".$formattedNumber."</td>";
?>