round a float number to next higher integer
Hi, I am sure this is very easy but for some reason I can't make this work.
I need to round incoming floating numbers to the next integers:
For example, an input value of 1.01 would return 2
Basically every float number that is between n and n+1 would return n+1 (int)
any help would be appreciated
thanks
Florent
oh sorry, I knew it wasn't that hard...
[expr (int($f1+1)]
-110
The problem with Roman's suggestion is that it will "round" an integral value to the next integer. A float value that happens to be an exact integer should remain unchanged.
This would dead easy with the ceil() function. The functions floor() and ceil() are standard functions that round either downwards or upwards. Unfortunately, [expr] doesn't provide either. Well, conversion to int is an implicit floor().
Anyway, here's a slightly simpler solution, using only simple arithmetic and comparison objects (no [expr], no [round]).
Thanks Roman and Peter.
You're right Peter, thanks, your solution is more elegant than mine.
I am comparing the incoming number with the rounded number (round 1). If the incoming number is greater than the rounded one, I add 1 to the rounded one and output that value.
oh yeah, that was the part which i missed. i even was about to write (int($f1))+1 first, but then changed it to int($f1+1 to make it look more sexy. :/
>but then changed it to int($f1+1 to make it look more sexy. :/
Stupid sexy expr.