Comments for "VB Shortcut for ceiling() function"
June 5, 2005, 11:08 pmVB Shortcut for ceiling() function
For some reason, Visual Basic does not include a ceiling() function, which takes a fractional number, and gives you the next higher integer. For example:
- ceiling(1) = 1
- ceiling(1.7) = 2
- ceiling(1.1314) = 2
- ceiling(0.1) = 1
- ceiling(-1.1) = -1
And so on.
Well, I needed a ceiling() function this evening, so I figured out a very cool trick, without resorting to creating a new function. To get the ceiling of a number x, do this:
(-(int(-(x))))
The int() of a negative number returns the next lower number, not what you'd think, but perfect for our ceiling function. Then, just get the negative of that result. (I use all the parenthesis to make sure VB understands exactly what I'm trying to do.)
Comments
You must be a Lottery Post member to post comments to a Blog.
Register for a FREE membership, or if you're already a member please Log In.



