PHPSuperBlog.com

Round down a decimal number to the nearest integer

In my past post, I talked about rounding up a decimal number to the nearest integer. This time I will show you how to round “down” a decimal number to the nearest integer. This time we use a function floor( ). It is very easy to use, all you have to do is to put the decimal number inside the brackets and it will convert for you. Here are some examples:

<?php 
echo floor(8.8); 
?>

we get: 8

<?php 
echo floor(-12.66);
?>

we get: -13

<?php 
echo floor(900.45563);
?>

we get: 900

Round up a decimal number to the nearest integer

If you want to round up a decimal number to the nearest integer. There is a function ceil( ) could do the job. It is very easy to use, all you have to do is to put the decimal number inside the brackets and it will convert the number. Here are some examples:

<?php 
echo ceil(8.8); 
?>

we get: 9

<?php 
echo ceil(-12.66);
?>

we get: -12

<?php 
echo ceil(900.45563);
?>

we get: 901

  • Categories

  • Useful Downloads