How can I make sure a float will always be rounded up with PHP?

Sotiris picture Sotiris · Feb 23, 2011 · Viewed 28.7k times · Source

I want to make sure a float in PHP is rounded up if any decimal is present, without worrying about mathematical rounding rules. This function would work as follows:

1.1 to 2
1.2 to 2
1.9 to 2
2.3 to 3
2.8 to 3

I know the round() function exists but I don't see any function for rounding up if any decimal is found. Is there any easy way to do this?

Answer

ircmaxell picture ircmaxell · Feb 23, 2011

Use the ceil function:

$number = ceil(1.1); //2