|
-
Oct 2nd, 2000, 12:06 PM
#1
Thread Starter
Addicted Member
How do I make Rounding, for example:
0.125 must be: 1
1.75 must be: 2
2.05 must be: 3
5.118 must be: 6
-
Oct 2nd, 2000, 12:10 PM
#2
Fanatic Member
Use Int or, if you have vb6 Fix.
Code:
Number = Int(Number + 1)
To get information on using Fix, look up msdn.microsoft.com
-
Oct 2nd, 2000, 12:22 PM
#3
Frenzied Member
Look what I've found:
Code:
Dim nr As Integer
nr = 1.9
MsgBox Int(nr + 1) 'Returns 3!
So instead use
Code:
Dim nr As Integer
nr = 1.99
Number = Int(nr + 1#)
'1# stands for 0.9999999999999999 (0.sixteen 9's)
'You have to use that 1# because otherwise you'll get:
nr = 1.00000000000001
MsgBox Int(nr + 0.999999999999999) '(0.fifteen 9's)
'Returns 1, not exactely what you want huh?
VB automaticly replaces the 0.sixteen 9's to 1#, thats how I discovered that cool huh?
have fun man!
[Edited by Jop on 10-02-2000 at 01:26 PM]
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 2nd, 2000, 01:34 PM
#4
Jop: In your first post you seemed surprised that Int(nr + 1) resulted in a value of 3. The reason that happens is that you defined nr as an Integer. When you attempted to store a non-integer value in it by writing nr = 1.9, VB made it an integer by rounding so it became = 2. The following illustrates that happening.
Dim nr As Integer
nr = 1.9
MsgBox nr
MsgBox Int(nr + 1) 'Returns 3!
-
Oct 2nd, 2000, 01:48 PM
#5
Frenzied Member
Yeah I realised that, I was retesting it and it didn't seem to work 
but now I have this strange thing:
Code:
Dim nr As Long 'LONG!
nr = 1.9
MsgBox nr '2
MsgBox Int(nr + 1#) '3
how do I make it so it doesn't round it itself before processing?
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 2nd, 2000, 01:52 PM
#6
Long is shorthand for Long Integer so it's still an integer, just one that will strore larger numbers than 32, 767. Use Double or Currency.
-
Oct 2nd, 2000, 01:58 PM
#7
Frenzied Member
Thanx, didn't knew about the Long Integer
I learn new things every day!
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 2nd, 2000, 01:58 PM
#8
Fanatic Member
Originally posted by MartinLiss
Use Double or Currency.
Or Single.
-
Oct 2nd, 2000, 02:01 PM
#9
Frenzied Member
What's the difference between double & single?
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 2nd, 2000, 02:05 PM
#10
Fanatic Member
I think it something like this: (look at msdn if you want to be sure)
Double:14 decimals
Single:7 decimals
-
Oct 2nd, 2000, 02:21 PM
#11
Thread Starter
Addicted Member
Thanks to you all ! I think I found a solution:
INT and FIX rounds downwards, so I make it this way:
Number! = Number! + 0.99
and it works !
-
Oct 2nd, 2000, 02:23 PM
#12
Thread Starter
Addicted Member
Sorry , it must be:
Number! = FIX(number + 0.99)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|