Results 1 to 15 of 15

Thread: [RESOLVED] Rounding Problem

Hybrid View

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2008
    Posts
    35

    Re: Rounding Problem

    hi cadman
    i have tried what u have told me but it was not working it will not give me values in zero

  2. #2
    Lively Member CADman's Avatar
    Join Date
    Aug 2007
    Posts
    92

    Re: Rounding Problem

    What is your data type? Integers and longs should strip decimals out.
    You may need to copy them into an integer or long first instead of single or double precision then do the divide, multiply as I suggested above.
    So for a number such as 7459.2 as an integer would be 7459. Divide by ten would be 745. Mult by ten gives 7450.
    Also the Fix function could be used to strip decimals like:
    Fix(7459.2/10)*10 would give 7450.

  3. #3
    Lively Member CADman's Avatar
    Join Date
    Aug 2007
    Posts
    92

    Re: Rounding Problem

    Oops, you wanted 7560 not 7450.
    7459.2
    Try: round(7459.2/10)*10

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Rounding Problem

    Code:
    Private Sub Form_Load()
    
    Dim lngValue As Long
    
    lngValue = 5823 '7459.2
    
    lngValue = Round(lngValue, 0)
    If Right$(lngValue, 1) < 5 Then
        MsgBox SymDown(lngValue, 0.1)
    Else
        MsgBox SymUp(lngValue, 0.1)
    End If
    
    End Sub
    Function SymDown(ByVal X As Double, _
             Optional ByVal Factor As Double = 1) As Double
      SymDown = Fix(X * Factor) / Factor
    End Function
    
    Function SymUp(ByVal X As Double, _
             Optional ByVal Factor As Double = 1) As Double
    Dim Temp As Double
      Temp = Fix(X * Factor)
      SymUp = (Temp + IIf(X = Temp, 0, Sgn(X))) / Factor
    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