Author 
Message 
Marc Alcid #1 / 13

rounding numbers (easy but you have to know it)
Hi, I would like to use a function that rounds numbers but like this : 12.4 = 13 12.1 =13 12.9 = 13 and not 12.1 =12 Anyone a clue?

Fri, 26 Dec 2003 21:49:13 GMT 


Steve Gomor #2 / 13

rounding numbers (easy but you have to know it)
Maybe Int(Value + .9). Assuming you only have one decimal place in your number. (meaning 12.01 won't work out to 13)
Quote: > Hi, > I would like to use a function that rounds numbers but like this : > 12.4 = 13 > 12.1 =13 > 12.9 = 13 > and not > 12.1 =12 > Anyone a clue?

Fri, 26 Dec 2003 22:18:22 GMT 


Phill W #3 / 13

rounding numbers (easy but you have to know it)
Marc, How about Int( n + 1 ) HTH, Phill W.
Quote: > Hi, > I would like to use a function that rounds numbers but like this : > 12.4 = 13 > 12.1 =13 > 12.9 = 13 > and not > 12.1 =12 > Anyone a clue?

Fri, 26 Dec 2003 22:16:44 GMT 


HR #4 / 13

rounding numbers (easy but you have to know it)
go to http://groups.google.com/ and in the serach, type in VB Round Up and you'll get about 6,500 ways to do it
Quote: > Maybe Int(Value + .9). Assuming you only have one decimal place in your > number. (meaning 12.01 won't work out to 13)
> > Hi, > > I would like to use a function that rounds numbers but like this : > > 12.4 = 13 > > 12.1 =13 > > 12.9 = 13 > > and not > > 12.1 =12 > > Anyone a clue?

Fri, 26 Dec 2003 22:22:14 GMT 


Steve Gomor #5 / 13

rounding numbers (easy but you have to know it)
Then 12 will round to 13  maybe not what he wants
Quote: > Marc, > How about > Int( n + 1 ) > HTH, > Phill W.
> > Hi, > > I would like to use a function that rounds numbers but like this : > > 12.4 = 13 > > 12.1 =13 > > 12.9 = 13 > > and not > > 12.1 =12 > > Anyone a clue?

Fri, 26 Dec 2003 22:28:33 GMT 


Rick Rothstei #6 / 13

rounding numbers (easy but you have to know it)
The correct answer has to do with what you want done with negative numbers. If you don't care about them, or if you want them treated "normally" (i.e., 2.22 rounds to 2), then If x <> Int(x) Then x= 1 + Int(x) End If But if you expect negative numbers to become more negative (i.e., 2.22 rounding to 3 mirroring the fact that 2.22 rounds to 3), then you will need to use this instead If x <> Int(d) Then x = Sgn(x) * (Abs(Fix(x)) + 1) End If By the way, it anyone is looking for simple, oneline solutions for the above, then the first group of statement could be written as x = Int(x) + 1 + (x = Int(x)) and the second group of statements like this x = Sgn(x) * (Abs(Fix(x)) + 1 + (x = Int(x))) to translate the logic directly, or these also work. The first is by Joe Foster and is faster (but uglier in my opinion <g>) than the second (which is by me) x = Int(Abs(x)) * Sgn(x) or x = Fix(x) + Sgn(x  Fix(x)) While these oneliners are "neat", they do tend to "hide" the logic of the operation a little. I prefer the oneliners myself, but you should use whatever you are comfortable with. Rick
Quote: > Hi, > I would like to use a function that rounds numbers but like this : > 12.4 = 13 > 12.1 =13 > 12.9 = 13 > and not > 12.1 =12 > Anyone a clue?
= Posted via Newsfeeds.Com, Uncensored Usenet News = http://www.newsfeeds.com  The #1 Newsgroup Service in the World! == Over 80,000 Newsgroups  16 Different Servers! =

Fri, 26 Dec 2003 22:38:23 GMT 


Rick Rothstei #7 / 13

rounding numbers (easy but you have to know it)
The correct answer has to do with what you want done with negative numbers. If you don't care about them, or if you want them treated "normally" (i.e., 2.22 rounds to 2), then If x <> Int(x) Then x= 1 + Int(x) End If But if you expect negative numbers to become more negative (i.e., 2.22 rounding to 3 mirroring the fact that 2.22 rounds to 3), then you will need to use this instead If x <> Int(d) Then x = Sgn(x) * (Abs(Fix(x)) + 1) End If By the way, it anyone is looking for simple, oneline solutions for the above, then the first group of statement could be written as x = Int(x) + 1 + (x = Int(x)) and the second group of statements like this x = Sgn(x) * (Abs(Fix(x)) + 1 + (x = Int(x))) to translate the logic directly, or these also work. The first is by Joe Foster and is faster (but uglier in my opinion <g>) than the second (which is by me) x = Int(Abs(x)) * Sgn(x) or x = Fix(x) + Sgn(x  Fix(x)) While these oneliners are "neat", they do tend to "hide" the logic of the operation a little. I prefer the oneliners myself, but you should use whatever you are comfortable with. Rick
Quote: > Hi, > I would like to use a function that rounds numbers but like this : > 12.4 = 13 > 12.1 =13 > 12.9 = 13 > and not > 12.1 =12 > Anyone a clue?
= Posted via Newsfeeds.Com, Uncensored Usenet News = http://www.newsfeeds.com  The #1 Newsgroup Service in the World! == Over 80,000 Newsgroups  16 Different Servers! =

Fri, 26 Dec 2003 22:40:40 GMT 


Scott Herber #8 / 13

rounding numbers (easy but you have to know it)
14.6 will then = 15 and not 14 MOD 1 might work (it worth a try)  Get your Free software at www.kirogl.co.uk
Quote: > Marc, > How about > Int( n + 1 ) > HTH, > Phill W.
> > Hi, > > I would like to use a function that rounds numbers but like this : > > 12.4 = 13 > > 12.1 =13 > > 12.9 = 13 > > and not > > 12.1 =12 > > Anyone a clue?

Sat, 27 Dec 2003 04:37:37 GMT 


Prince of Insufficient Ligh #9 / 13

rounding numbers (easy but you have to know it)
: 14.6 will then = 15 and not 14 : MOD 1 might work (it worth a try) :> > 12.1 =13 :> > 12.9 = 13 Given the specs, I'd say Int(n + 1) does it... he doesn't want it to equal 14.  Ben Garrison * cs1322 TA / ProgDev * www.bengarrison.net \ Ecclesiastes 11:5 As you do not know the path of the wind, or how \ the body is formed in a mother's womb, so you cannot understand the \ work of God, the Maker of all things.

Sat, 27 Dec 2003 04:53:40 GMT 


Joe #10 / 13

rounding numbers (easy but you have to know it)
Quote:
> Hi, > I would like to use a function that rounds numbers but like this : > 12.4 = 13 > 12.1 =13 > 12.9 = 13 > and not > 12.1 =12 > Anyone a clue?
To round up, so 12.9 becomes 13 but 12.9 becomes 12: x = int(x) To round away from zero, so 12.9 becomes 13 instead of 12: x = int(abs(x)) * sgn(x) You might also want to add an offset, since even though 12.00000000000001 will display as 12, either of those expressions above will turn it into 13, giving you something more like these: x = int(0.00001  x) or x = int(0.00001  abs(x)) * sgn(x) 
WARNING: I cannot be held responsible for the above They're coming to because my cats have apparently learned to type. take me away, ha ha!

Sat, 27 Dec 2003 08:14:28 GMT 


BeastFi #11 / 13

rounding numbers (easy but you have to know it)
Maybe try this... N = Fix(N + 0.999999999) ...which is the same as... N = Sgn(N + 0.999999999) * Int(Abs(N + 0.999999999)) 12.1 returns 13 12.1 returns 11 BTW, if the number is something like 12.0000000001 then it doesn't deserve to be rounded up ;) Quote:
> Hi, > I would like to use a function that rounds numbers but like this : > 12.4 = 13 > 12.1 =13 > 12.9 = 13 > and not > 12.1 =12 > Anyone a clue?

Sat, 27 Dec 2003 12:39:11 GMT 


Joachim Van Brand #12 / 13

rounding numbers (easy but you have to know it)
Okay... I could have sworn there was a round function as well... I'm not on a computer with VB on it right now, but I think I saw it used in VB6 a few days ago... Joachim Quote:
> Hi, > I would like to use a function that rounds numbers but like this : > 12.4 = 13 > 12.1 =13 > 12.9 = 13 > and not > 12.1 =12 > Anyone a clue?

Tue, 13 Jan 2004 11:26:02 GMT 


Paul #13 / 13

rounding numbers (easy but you have to know it)
Wasn't this message from many weeks ago? Our battle is complete. You were a stimulating opponent.
Quote: > Okay... I could have sworn there was a round function as well... I'm not > on a computer with VB on it right now, but I think I saw it used in VB6 > a > few days ago... > Joachim
> > Hi, > > I would like to use a function that rounds numbers but like this : > > 12.4 = 13 > > 12.1 =13 > > 12.9 = 13 > > and not > > 12.1 =12 > > Anyone a clue?

Tue, 13 Jan 2004 11:27:26 GMT 

