Zend - The PHP Company




Math

Add Code


Round up  

Type: code fragment
Added by: acecool
Entered: 08/08/2004
Last modified: 08/12/2003
Rating: - (fewer than 3 votes)
Views: 3811
Takes a number like 1000.000001 and rounds it to 1001, or 1000.9 and rounds it to 1001 I made this for my paginator which gets the total pages then divides by amount per page, sometimes it returns 1.1 or 1.00001 etc, so it rounds it up for a solid number to use for the paginator


Heres a nice function I made for my pagination that rounds to the next number if the number is greater than the whole number.

EX: 2.000001 will return 3
2.5 will return 3
2 will return 2
1.9 or 1.3 etc will return 2

Can use it as long as copyright remains intact.

<?php
function round_up($Number) {
    
// Copyright Josh Acecool M http://www.acecoolco.com
    
if ($Number number_format($Number"0")) {
        
$Number round($Number);
        
$Number++;
    }
    else
    {
        
$Number number_format($Number"0");
    }
    return 
$Number;
}
?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories