ROUND up

S

shank

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
 
E

Evertjan.

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
 
M

MyndPhlyp

shank said:
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().
 
B

Bullschmidt

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top