Round down a decimal number to the nearest integer

Posted by Shek on April 24, 2008 under PHP | 2 Comments to Read | Total View: 3,908 views

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

Not what you want? Try a Search

  • Steve said,

    Sorry sir, but is it possible to round the decimal to the next 5 cents or 10 cents example below ?

    USD 1.53 round to USD 1.55
    USD 1.58 round to USD 1.60

    Thanks

  • Shek said,

    For your reference:

    http://www.php.net/manual/en/function.round.php

    Cheers!

Add A Comment

*