Are there any PHP functions or methods that can assist in formatting numbers, such as restricting them to 2 digits?

When working with numbers in PHP, you may need to format them in a specific way, such as restricting them to a certain number of digits. One way to achieve this is by using the number_format() function in PHP. This function allows you to format a number with grouped thousands and decimal points. By specifying the number of decimal places you want to display, you can easily restrict the number to 2 digits.

$number = 123.456789;
$formatted_number = number_format($number, 2);
echo $formatted_number; // Output: 123.46