Are there any potential pitfalls in using round() function in PHP for rounding numbers?

One potential pitfall in using the round() function in PHP is that it uses traditional rounding rules, which may not always produce the desired results. To address this issue, you can use a custom rounding function that allows you to specify the number of decimal places and the rounding method.

function custom_round($number, $precision = 0, $method = PHP_ROUND_HALF_UP) {
    $factor = 10 ** $precision;
    return round($number * $factor, 0, $method) / $factor;
}

// Example usage
$number = 3.456;
$rounded_number = custom_round($number, 2, PHP_ROUND_HALF_UP);
echo $rounded_number; // Output: 3.46