Example 1 — Round to Decimal Places
Pass the number first and the number of decimals second.
<?php
echo round(3.14159, 2), PHP_EOL;
echo round(2.5), PHP_EOL;
echo round(-2.5), PHP_EOL;
echo round(1.95583, 2), PHP_EOL; How It Works
- round(3.14159, 2) keeps two decimals and returns 3.14.
- round(2.5) rounds half up to 3.
- round(-2.5) rounds away from zero to -3.
- round(1.95583, 2) looks at the third decimal (5) and rounds up to 1.96.

