How can PHP be used to add and format numbers with a specific precision?

To add and format numbers with a specific precision in PHP, you can use the number_format() function. This function allows you to specify the number of decimal places you want to display for a given number. Simply pass the number you want to format as the first parameter, the number of decimal places as the second parameter, and optional parameters for decimal separator, thousands separator, and negative number handling.

$number = 123.456789;
$precision = 2;

$formatted_number = number_format($number, $precision);

echo $formatted_number; // Output: 123.46