+ Reply to Thread
Results 1 to 4 of 4

Problem with the round function

  1. #1
    Patrick
    Guest

    Problem with the round function

    Hi every1!!!

    Need help understanding whats wrong with this function.
    All my variables are declared as Double.

    here's my code:

    test = Var_clStructural * 1.65

    "for this example,Var_clStructural = 4.5"

    test=7.425

    If i use the round like this:

    test = Round(Var_clStructural *1.65,2)

    I should get: 7.43, but im not and its frustrating cuz i dont see why its
    rounding-up like that.

    Can anyone point me in the right direction please!!!

    If i asign the 7.425 to a cell, thats formated to numbers with 2 decimal im
    ok,why doesnt-it work in VBA.

    Thx alot for your help guys!!

    PAtrick




  2. #2
    Tom Ogilvy
    Guest

    Re: Problem with the round function

    VBA rounds up or down to the even number. Excel rounds up for 5 or above.

    from the immediate window:
    Var_clStructural = 4.5
    ? Round(Var_clStructural *1.65,2)
    7.42
    ? application.Round(Var_clStructural *1.65,2)
    7.43
    ? Var_clStructural *1.65
    7.425

    So you can use Application.Round to get the worksheet round.

    http://support.microsoft.com/default...b;en-us;194983
    PRB: Round Function different in VBA 6 and Excel Spreadsheet

    http://www.xldynamic.com/source/xld.Rounding.html#vba

    http://support.microsoft.com/default...b;en-us;196652
    How To Implement Custom Rounding Procedures

    --
    Regards,
    Tom Ogilvy


    "Patrick" <[email protected]> wrote in message
    news:[email protected]...
    > Hi every1!!!
    >
    > Need help understanding whats wrong with this function.
    > All my variables are declared as Double.
    >
    > here's my code:
    >
    > test = Var_clStructural * 1.65
    >
    > "for this example,Var_clStructural = 4.5"
    >
    > test=7.425
    >
    > If i use the round like this:
    >
    > test = Round(Var_clStructural *1.65,2)
    >
    > I should get: 7.43, but im not and its frustrating cuz i dont see why its
    > rounding-up like that.
    >
    > Can anyone point me in the right direction please!!!
    >
    > If i asign the 7.425 to a cell, thats formated to numbers with 2 decimal

    im
    > ok,why doesnt-it work in VBA.
    >
    > Thx alot for your help guys!!
    >
    > PAtrick
    >
    >
    >




  3. #3
    Don Guillett
    Guest

    Re: Problem with the round function

    try this.
    Sub doround()
    X = 4.5
    y = 1.65
    MsgBox Application.RoundUp(X * y, 2)
    End Sub

    --
    Don Guillett
    SalesAid Software
    [email protected]
    "Patrick" <[email protected]> wrote in message
    news:[email protected]...
    > Hi every1!!!
    >
    > Need help understanding whats wrong with this function.
    > All my variables are declared as Double.
    >
    > here's my code:
    >
    > test = Var_clStructural * 1.65
    >
    > "for this example,Var_clStructural = 4.5"
    >
    > test=7.425
    >
    > If i use the round like this:
    >
    > test = Round(Var_clStructural *1.65,2)
    >
    > I should get: 7.43, but im not and its frustrating cuz i dont see why its
    > rounding-up like that.
    >
    > Can anyone point me in the right direction please!!!
    >
    > If i asign the 7.425 to a cell, thats formated to numbers with 2 decimal

    im
    > ok,why doesnt-it work in VBA.
    >
    > Thx alot for your help guys!!
    >
    > PAtrick
    >
    >
    >




  4. #4
    Don Guillett
    Guest

    Re: Problem with the round function

    or just round if that is what is desired

    --
    Don Guillett
    SalesAid Software
    [email protected]
    "Don Guillett" <[email protected]> wrote in message
    news:[email protected]...
    > try this.
    > Sub doround()
    > X = 4.5
    > y = 1.65
    > MsgBox Application.RoundUp(X * y, 2)
    > End Sub
    >
    > --
    > Don Guillett
    > SalesAid Software
    > [email protected]
    > "Patrick" <[email protected]> wrote in message
    > news:[email protected]...
    > > Hi every1!!!
    > >
    > > Need help understanding whats wrong with this function.
    > > All my variables are declared as Double.
    > >
    > > here's my code:
    > >
    > > test = Var_clStructural * 1.65
    > >
    > > "for this example,Var_clStructural = 4.5"
    > >
    > > test=7.425
    > >
    > > If i use the round like this:
    > >
    > > test = Round(Var_clStructural *1.65,2)
    > >
    > > I should get: 7.43, but im not and its frustrating cuz i dont see why

    its
    > > rounding-up like that.
    > >
    > > Can anyone point me in the right direction please!!!
    > >
    > > If i asign the 7.425 to a cell, thats formated to numbers with 2 decimal

    > im
    > > ok,why doesnt-it work in VBA.
    > >
    > > Thx alot for your help guys!!
    > >
    > > PAtrick
    > >
    > >
    > >

    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1