Velocity Reviews > ROUND up

# ROUND up

shank
Guest
Posts: n/a

 10-31-2005
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

Evertjan.
Guest
Posts: n/a

 10-31-2005
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)

MyndPhlyp
Guest
Posts: n/a

 10-31-2005

"shank" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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().

Bullschmidt
Guest
Posts: n/a

 11-02-2005
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 ***