ROUND up

Discussion in 'ASP General' started by shank, Oct 31, 2005.

  1. shank

    shank Guest

    I have the following equation.

    <% varWT = Round(CInt((rsFreePack.Fields.Item("Weight").Value)) +
    CInt(Session("w"))) %>

    Assume....
    Round(CInt((rsFreePack.Fields.Item("Weight").Value)) = .12
    CInt(Session("w")) = 30

    How can I get it to always ROUND up to 31 ...?

    thanks
     
    shank, Oct 31, 2005
    #1
    1. Advertising

  2. shank

    Evertjan. Guest

    shank wrote on 31 okt 2005 in microsoft.public.inetserver.asp.general:

    > I have the following equation.
    >
    > <% varWT = Round(CInt((rsFreePack.Fields.Item("Weight").Value)) +
    > CInt(Session("w"))) %>
    >
    > Assume....
    > Round(CInt((rsFreePack.Fields.Item("Weight").Value)) = .12


    Impossible assumption, since that would be rounded to 0

    > CInt(Session("w")) = 30
    >
    > How can I get it to always ROUND up to 31 ...?


    a = .12
    b = 30
    c = a + b '30.12

    if int(c)<c then c = int(c) + 1



    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Oct 31, 2005
    #2
    1. Advertising

  3. shank

    MyndPhlyp Guest

    "shank" <> wrote in message
    news:...
    > I have the following equation.
    >
    > <% varWT = Round(CInt((rsFreePack.Fields.Item("Weight").Value)) +
    > CInt(Session("w"))) %>
    >
    > Assume....
    > Round(CInt((rsFreePack.Fields.Item("Weight").Value)) = .12
    > CInt(Session("w")) = 30
    >
    > How can I get it to always ROUND up to 31 ...?
    >
    > thanks


    How 'bout ...

    Test to see if CInt(rsFreePack.Fields.Item("Weight").Value) <
    CDbl(rsFreePack.Fields.Item("Weight").Value) and, if so, add 1 to
    CInt(rsFreePack.Fields.Item("Weight").Value) otherwise just use
    CInt(rsFreePack.Fields.Item("Weight").Value).

    CInt() truncates the fractional part as does CLng().
     
    MyndPhlyp, Oct 31, 2005
    #3
  4. shank

    Bullschmidt Guest

    Here's a RoundUp function I have written that hopefully might help:

    Function jpsvbRoundUp(pvarNum, pvarDecimals)
    ' Purpose: Round up.
    ' Remarks: Usually makes numbers farther from 0 even if the important
    digit is less than 5.
    ' Examples:
    ' jpsvbRoundUp(3.451, 2) -> 3.46
    ' jpsvbRoundUp(-3.451, 2) -> -3.46

    ' Dim var.
    Dim varNum
    Dim varDecimals
    Dim varBigValue

    ' Quick exit if either item not numeric.
    If (Not IsNumeric(pvarNum)) Or (Not IsNumeric(pvarDecimals)) Then
    jpsvbRoundUp = 0
    Exit Function
    End If

    ' Set var.
    varNum = pvarNum

    ' Round decimals to an integer in case not one already.
    ' (Note that VBScript's Round() also rounds its decimals parameter.)
    ' (If used CInt() instead of Round() it could have had a rounding error
    ' if important digit were 5.)
    varDecimals = Round(pvarDecimals, 0)

    ' Convert 3.456 to 2 decimal places up to be 345.6
    varBigValue = varNum * 10 ^ varDecimals

    If varBigValue = Fix(varBigValue) Then
    jpsvbRoundUp = varBigValue / 10 ^ varDecimals
    Else
    ' Add 1 to the above 345.6 to get 346.6.
    ' (But if the orig number is neg., then subtract 1 instead.)
    ' Then chop off the fractional .6 to leave 346.
    ' Then convert 346 back down to 3.46.
    If varNum >= 0 Then
    jpsvbRoundUp = Fix(varBigValue + 1) / 10 ^ varDecimals
    Else
    jpsvbRoundUp = Fix(varBigValue - 1) / 10 ^ varDecimals
    End If
    End If
    End Function

    Best regards,
    J. Paul Schmidt, Freelance Web and Database Developer
    http://www.Bullschmidt.com
    Access Database Sample, Web Database Sample, ASP Design Tips

    <<
    I have the following equation.

    <% varWT = Round(CInt((rsFreePack.Fields.Item("Weight").Value)) +
    CInt(Session("w"))) %>

    Assume....
    Round(CInt((rsFreePack.Fields.Item("Weight").Value)) = .12
    CInt(Session("w")) = 30

    How can I get it to always ROUND up to 31 ...?

    thanks
    >>


    *** Sent via Developersdex http://www.developersdex.com ***
     
    Bullschmidt, Nov 2, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ruslan

    Round up

    Ruslan, Aug 3, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    1,707
    Ruslan
    Aug 4, 2003
  2. Peter Row
    Replies:
    1
    Views:
    692
    vMike
    Nov 26, 2003
  3. Replies:
    0
    Views:
    1,098
  4. OliverMarchand

    Float.round - should it be round-to-even

    OliverMarchand, Apr 12, 2006, in forum: Ruby
    Replies:
    2
    Views:
    225
    OliverMarchand
    Apr 12, 2006
  5. cerr

    reading file round and round

    cerr, Mar 19, 2010, in forum: Perl Misc
    Replies:
    6
    Views:
    183
    Peter J. Holzer
    Mar 20, 2010
Loading...

Share This Page