Results 1 to 5 of 5

Thread: How to get number after dot? (14.5)

  1. #1
    Stiletto
    Guest

    How to get number after dot? (14.5)

    Heya,
    I got a simple question: How can i get the value after the dot?
    for example:
    Code:
    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

  2. #2
    Destined Soul
    Guest
    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

  3. #3
    Stiletto
    Guest
    Hey, i'm kinda newb in VB
    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?

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    format(timeserial(0,0,233),"nn.ss")
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Behemoth
    Guest
    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))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width