# ROUND up

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

1. ### shankGuest

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

2. ### 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

3. ### MyndPhlypGuest

"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
4. ### BullschmidtGuest

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