Results 1 to 10 of 10

Thread: Checking number of dec.places

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2001
    Location
    UK
    Posts
    38

    Checking number of dec.places

    with regards to a thread that I posted earlier dealing with rounding down - I found the following formula for achieving this :

    tempcalc = int(tempcalc * 100 + 0.5) / 100

    if tempcalc = 0.016 - u get 0.02

    if tempcalc = 0.015 - u get 0.01

    which is the result I wanted.

    Further to this, how do I return just the decimal part of a double defined variable & know how many decimal places there are?

    eg - if I have 12.000156

    I just want to return 000156 without the dec.point & know that I have 6 figures.

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Private Sub Command2_Click()
    2.     MsgBox Split(Str(12.000156), ".")(1)
    3. End Sub
    -= a peet post =-

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2001
    Location
    UK
    Posts
    38

    Thumbs up

    nice one - cheers

  4. #4
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Um peet, wouldn't it be?

    MsgBox Len(Split(Str(12.000156), ".")(1))

    ?

    as he wants to know the number of decimal places, not all of them?

  5. #5
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Originally posted by da_silvy
    Um peet, wouldn't it be?

    MsgBox Len(Split(Str(12.000156), ".")(1))

    ?

    as he wants to know the number of decimal places, not all of them?
    yes... I recon he wants that as well, but I think that he might have figured out the Len function

    to be honest... I only read the first part of the question. ..
    I just want to return 000156 without the dec.point


    is a better version with less white spots in the transp. area
    -= a peet post =-

  6. #6
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610
    How about adding this so you get a usable decimal

    Code:
    Dim Ans As Double
    
    Ans = 12.000156 - (Int (12.000156))
    This space for rent...

  7. #7
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Originally posted by steve65
    How about adding this so you get a usable decimal

    Code:
    Dim Ans As Double
    
    Ans = 12.000156 - (Int (12.000156))
    thanks alot Steve

    now I feel really stupid *hrmpf*


    -= a peet post =-

  8. #8
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610
    No problem just remeber this day when I ask my next stupid question
    This space for rent...

  9. #9
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Hehehehe,

    If it's on VBA i'm set.

    I've answered a few of them recently

  10. #10
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Now, to answer his question
    VB Code:
    1. Dim DecPlaces As Double
    2. DecPlaces = Len(12.000156 - (Int (12.000156)))

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