round to 2 decimal places php
snippet in php

php round 2 decimals

user6703

$value = 4.96754;
round($value, 2);
//returns 4.97

php round up

user1324

//round up to nearest integer
echo(ceil(0.60) . "<br>");
//result 1

round to 2 decimal places php

user1895

round(520.34345, 2);   // 520.34

php round up

user609


<?php
echo 'Rounding modes with 9.5' . PHP_EOL;
var_dump(round(9.5, 0, PHP_ROUND_HALF_UP));
var_dump(round(9.5, 0, PHP_ROUND_HALF_DOWN));
var_dump(round(9.5, 0, PHP_ROUND_HALF_EVEN));
var_dump(round(9.5, 0, PHP_ROUND_HALF_ODD));

echo 'Rounding modes with 8.5' . PHP_EOL;
var_dump(round(8.5, 0, PHP_ROUND_HALF_UP));
var_dump(round(8.5, 0, PHP_ROUND_HALF_DOWN));
var_dump(round(8.5, 0, PHP_ROUND_HALF_EVEN));
var_dump(round(8.5, 0, PHP_ROUND_HALF_ODD));
?>