ALWAYS ROUND UP

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to write a round-up function that ALWAYS rounds up. For example,
I want it to round 5.2 to 6. What am I missing:

Function Round_Up(dNum As Double, nDP As Integer) As Double
dNum = Int(dNum * 10 ^ nDP + 0.5) / 10 ^ nDP
Round_Up = dNum
End Function

Expr1: Round_Up([DimmWt],0)
'where DimmWt = 5.2, it returns a value of 5, not desired 6

Thanks.
Sammie
 
Hi -

Try this:

Function roundup(ByVal pNum As Double) As Integer
'*******************************************
'Purpose: To round pnum up to the nearest plevel
'Inputs: ? roundup(5.2)
'Output: 6
'*******************************************
roundup = IIf(pNum > Int(pNum), Int(pNum) + 1, pNum)
End Function

HTH - Bob
I am trying to write a round-up function that ALWAYS rounds up. For example,
I want it to round 5.2 to 6. What am I missing:

Function Round_Up(dNum As Double, nDP As Integer) As Double
dNum = Int(dNum * 10 ^ nDP + 0.5) / 10 ^ nDP
Round_Up = dNum
End Function

Expr1: Round_Up([DimmWt],0)
'where DimmWt = 5.2, it returns a value of 5, not desired 6

Thanks.
Sammie
 
raskew via AccessMonster.com said:
Hi -

Try this:

Function roundup(ByVal pNum As Double) As Integer
'*******************************************
'Purpose: To round pnum up to the nearest plevel
'Inputs: ? roundup(5.2)
'Output: 6
'*******************************************
roundup = IIf(pNum > Int(pNum), Int(pNum) + 1, pNum)
End Function

HTH - Bob
I am trying to write a round-up function that ALWAYS rounds up. For example,
I want it to round 5.2 to 6. What am I missing:

Function Round_Up(dNum As Double, nDP As Integer) As Double
dNum = Int(dNum * 10 ^ nDP + 0.5) / 10 ^ nDP
Round_Up = dNum
End Function

Expr1: Round_Up([DimmWt],0)
'where DimmWt = 5.2, it returns a value of 5, not desired 6

Thanks.
Sammie
Sammie
 
Function roundup(ByVal pNum As Variant) As Variant
'*******************************************
'Purpose: To round pnum up to the nearest plevel
'Inputs: ? roundup(5.2)
'Output: 6
'*******************************************
If IsNumeric(pNum) Then
roundup = IIf(pNum > Int(pNum), Int(pNum) + 1, pNum)
Else
Roundup = pNum
End if
End Function

If you need to accept nulls then you need to change the input type and
the output type.

By the way, if you are always rounding up to the next integer value and
your are always starting with a positive number

-Int(-[YourField]) will work without using a function.

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================

raskew via AccessMonster.com said:
Hi -

Try this:

Function roundup(ByVal pNum As Double) As Integer
'*******************************************
'Purpose: To round pnum up to the nearest plevel
'Inputs: ? roundup(5.2)
'Output: 6
'*******************************************
roundup = IIf(pNum > Int(pNum), Int(pNum) + 1, pNum)
End Function

HTH - Bob
I am trying to write a round-up function that ALWAYS rounds up. For example,
I want it to round 5.2 to 6. What am I missing:

Function Round_Up(dNum As Double, nDP As Integer) As Double
dNum = Int(dNum * 10 ^ nDP + 0.5) / 10 ^ nDP
Round_Up = dNum
End Function

Expr1: Round_Up([DimmWt],0)
'where DimmWt = 5.2, it returns a value of 5, not desired 6

Thanks.
Sammie
Sammie
 
Back
Top