tags:

views:

1925

answers:

4

Anyone has ever programmed a PHP (or perl) function to get the ceiling value Excel style?

TIA

Roberto

+2  A: 

Sorry, not quite clear what 'Excel style' is, but PHP has a ceil function.

Paolo Bergantino
A: 

http://us2.php.net/manual/en/function.ceil.php

This does it.

cazlab
+7  A: 

"Microsoft Excel's ceiling function does not follow the mathematical definition, but rather as with (int) operator in C, it is a mixture of the floor and ceiling function: for x ≥ 0 it returns ceiling(x), and for x < 0 it returns floor(x). This has followed through to the Office Open XML file format. For example, CEILING(-4.5) returns -5. A mathematical ceiling function can be emulated in Excel by using the formula "-INT(-value)" (please note that this is not a general rule, as it depends on Excel's INT function, which behaves differently that most programming languages)." - from wikipedia

If php's built in ceil function isn't working right you could make a new function like

function excel_ceil($num){
    return ($num>0)?ceil($num):floor($num);
}

Hope that helps

Jacob
A: 

Wouldn't you use round for this instead of calling ceil if it's too high, or floor if it's too low?

Ryan Bigg