Results 1 to 9 of 9

Thread: truncating???

  1. #1

    Thread Starter
    Junior Member BUTTMAN's Avatar
    Join Date
    Apr 2002
    Posts
    27

    truncating???

    example..

    148.87

    i just want to get 148 without .87
    is there such a function?
    without rounding it of course..

    thankx!!!!
    =====
    To follow the path:
    look to the master,
    follow the master,
    walk with the master,
    see through the master,
    become the master.

  2. #2
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Int() returns the integer portion of a number.

    Int(148.87) = 148

  3. #3
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    msgbox fix(148.87) 'positives
    msgbox fix(-148.87) 'and negatives too
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  4. #4
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Dim strThis As String, intDec As Integer

    strThis = "148.87"
    intDec = InStr(1, strThis, ".")

    MsgBox Left(strThis, intDec - 1)

    <edit>guess it depends on where you're coming from</edit>
    Please rate my post.

  5. #5
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Originally posted by DiGiTaIErRoR
    Int() returns the integer portion of a number.

    Int(148.87) = 148
    if you have anegative number, Int will minus 1 to the number:

    MsgBox Int(-147.83) 'returns -148
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  6. #6
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    He didn't mention negative numbers.

  7. #7

    Thread Starter
    Junior Member BUTTMAN's Avatar
    Join Date
    Apr 2002
    Posts
    27
    thankx everyone...

    really nice forum!!!
    =====
    To follow the path:
    look to the master,
    follow the master,
    walk with the master,
    see through the master,
    become the master.

  8. #8
    Addicted Member
    Join Date
    Jul 2002
    Location
    Toronto, ON Canada
    Posts
    153
    Try this:
    msgbox number \ 1
    it'll return an int.

  9. #9
    Member
    Join Date
    Aug 2002
    Posts
    33

    Truncate

    This truncates a value to a number of decimal places and returns the value.

    Public Function Truncate(Value As Double, Places As Integer) As double
    Dim tp As String
    Dim P As Integer

    tp = Format$(Value, "0." & String$(Places + 3, "0"))
    P = InStr(1, tp, ".")

    Truncate = cdbl(Left$(tp, P + Places))
    End Function

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