floor ceil php code example

Example 1: floor ceil php

echo(floor(0.60) . "<br>"); // 0
echo(floor(0.40) . "<br>"); // 0
echo(floor(5) . "<br>"); // 5
echo(floor(5.1) . "<br>"); //5
echo(floor(-5.1) . "<br>"); // -6
echo(floor(-5.9)); // -6

echo(ceil(0.60) . "<br>"); // 1
echo(ceil(0.40) . "<br>"); // 1
echo(ceil(5) . "<br>"); // 5
echo(ceil(5.1) . "<br>"); // 6
echo(ceil(-5.1) . "<br>"); // -5
echo(ceil(-5.9)); // -5

Example 2: php round up

<?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));
?>

Tags:

Php Example