Arithmatic Module Converts to Text

S

Scott

I have the following module and when I use it in a query,
Round([Quantity]*[UnitPrice]), it converts the data values to text. How do I
make it leave the data as currency or a number?

Option Explicit
Const Factor = 100

Function RoundC2(x)
'
' Rounds number to 2 decimal places
' Uses arithmatic rounding
' Designed for use with Currency values
'
If IsNull(x) Then
RoundC2 = Null
Else
RoundC2 = CCur(Int(x * Factor + 0.5) / Factor)
End If
End Function

Function Round(x)
Round = CCur(Int(x * Factor + 0.5) / Factor)
End Function
Function Round0(x)
Round0 = CCur(Int(x * 1 + 0.5) / 1)
End Function
Function TruncCC(x)
TruncCC = Int(x * 1) / 1
End Function

Thanks,

Scott
 
B

Brendan Reynolds

You haven't specified the data type of your functions, so they are
defaulting to Variant. Try specifying the data type you want like so ...

'Function RoundC2(x)
Function RoundC2(x) As Currency
 
S

Scott

That worked, thank you!
Scott

Brendan Reynolds said:
You haven't specified the data type of your functions, so they are
defaulting to Variant. Try specifying the data type you want like so ...

'Function RoundC2(x)
Function RoundC2(x) As Currency

--
Brendan Reynolds

Scott said:
I have the following module and when I use it in a query,
Round([Quantity]*[UnitPrice]), it converts the data values to text. How
do I
make it leave the data as currency or a number?

Option Explicit
Const Factor = 100

Function RoundC2(x)
'
' Rounds number to 2 decimal places
' Uses arithmatic rounding
' Designed for use with Currency values
'
If IsNull(x) Then
RoundC2 = Null
Else
RoundC2 = CCur(Int(x * Factor + 0.5) / Factor)
End If
End Function

Function Round(x)
Round = CCur(Int(x * Factor + 0.5) / Factor)
End Function
Function Round0(x)
Round0 = CCur(Int(x * 1 + 0.5) / 1)
End Function
Function TruncCC(x)
TruncCC = Int(x * 1) / 1
End Function

Thanks,

Scott
 
Top