Arithmatic Module Converts to Text

G

Guest

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
 
G

Guest

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
 

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

Top