Groups | Blog | Home
all groups > sql server reporting services > february 2006 >

sql server reporting services : Divide by zero



Candy
2/23/2006 2:00:28 PM
I'm using Toolman's Public function and it's working as far as the divide by
zero, however, I'm trying to get a percentage. When I pass the two
parameters to it, if the result is 100.% it shows up. If it's anything else,
it shows 0.0%. Here is the function and the code.

Public Function DivideBy(ByVal exp1, ByVal exp2)
If exp1 = 0 Then
DivideBy = 0
Else
DivideBy = exp1 / exp2
End If
End Function

=code.DivideBy

( Fields!Under120_1.Value, Fields!TotalRecs.Value )

Any help is appreciated.
--
Steve MunLeeuw
2/23/2006 4:04:02 PM
Sounds like a datatype issue, maybe there is a conversion to int in your
expression?

I tried the expression:
=Code.DivideBy(5, 100) * 100

and it doesn't return zero or 100.

I wrapped a CInt() around it and I get that behavior.:

=CInt(Code.DivideBy(5, 100))

The CInt forces either a 0 or 1, then it's converted to percent.

[quoted text, click to view]

toolman
2/24/2006 9:50:44 AM
Try CDbl() instead of CInt()
Also, make sure the values being passed are not integer values
AddThis Social Bookmark Button