How can the PHP functions round() and sprintf() be utilized to format numbers?
To format numbers in PHP, the round() function can be used to round a number to a specified number of decimal places, while the sprintf() function can be used to format a number with a specified number of decimal places and additional formatting options. Example:
$number = 123.456789;
// Round the number to 2 decimal places
$roundedNumber = round($number, 2);
// Format the rounded number with 2 decimal places using sprintf
$formattedNumber = sprintf("%.2f", $roundedNumber);
echo $formattedNumber; // Output: 123.46