Click to See Complete Forum and Search --> : How to get number after dot? (14.5)
Stiletto
Jul 5th, 2001, 11:35 AM
Heya,
I got a simple question: How can i get the value after the dot?
for example:
Dim Num As Integer
Num = 5 / 2
In this case, the value of Num will b 2, since 5 / 2 is 2.5 but Num is Integer. Just like this, I want to get the value of the number AFTER THE DOT (in this example: 5 (NOT 0.5))
Can some1 plz help me here and tell me which variant can do that and how to do that?
tnx
Destined Soul
Jul 5th, 2001, 12:03 PM
Are you wanting only the single number that occurs after the decimal, or are you wanting everything past the decimal?
ie: if your number is 2.817201, do you want:
A: 8
B: 817201
C: 8.17201
A & C are easy. It's:
Dim Orig As Single
Dim Num As Integer
Orig = 2.817201
Num = 10*(Orig - Int(Orig))
' Now we have C, if you want A, just do
Num = Int(Num)
This, of course, is without rounding. For that you would use Num = Int(Num+0.5). At least, that's how I would do it.
Destined
Stiletto
Jul 5th, 2001, 12:14 PM
Hey, i'm kinda newb in VB :D
can ya help me more?
i have a number which is in seconds, i want to translate it to minutes.
for example, i want 233 (secs) to bcome 3.53 (mins)
can ya tell me how to do it?
kedaman
Jul 5th, 2001, 12:57 PM
format(timeserial(0,0,233),"nn.ss")
Behemoth
Jul 17th, 2001, 08:54 AM
Originally posted by Destined Soul
Are you wanting only the single number that occurs after the decimal, or are you wanting everything past the decimal?
ie: if your number is 2.817201, do you want:
A: 8
B: 817201
C: 8.17201
A & C are easy. It's:
Dim Orig As Single
Dim Num As Integer
Orig = 2.817201
Num = 10*(Orig - Int(Orig))
' Now we have C, if you want A, just do
Num = Int(Num)
This, of course, is without rounding. For that you would use Num = Int(Num+0.5). At least, that's how I would do it.
Destined
-- for B, simply multply the number by (10^(len(number))
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.