Welcome Guest
( Log In | Register )
The time is now 10:40 pm
All times shown are
Eastern Time (GMT-5:00)

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.)

Entry #152

Comments

1.
JADELotteryComment by JADELottery - June 6, 2005, 10:00 pm
great work. i'll have to file this one away in back of my brain somewhere. i know i'll need it some day.

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.