PDA

View Full Version : Simple Percentage Calculation?


Running Bear
06-11-2003, 03:04 PM
Hi,

I'm using ASP to perform a simple percentage calculation and I'm getting incorrect results????


Dim pct ' % calculated from the vals of x & y
Dim x ' Value of the count x 3
Dim y ' Value to be used to calc %
Dim z ' Value returned from the date difference

x = 102
y = 102

pct = (100 \ x) * y

returns 0 - !!!??

Here are some more examples -

X=15
Y =13
(100\15)*13=78%

X=102
Y =102
(100\102)*102=0%

X=27
Y =26
(100\27)*26=78%

X=6
Y =6
(100\6)*6=96%

X=24
Y =21
(100\24)*21=84%

X=6
Y =6
(100\6)*6=96%

X=6
Y =6
(100\6)*6=96%


Any help or guidance would/will be greatly appreciated :D

Cheers Al

bostjank
06-11-2003, 03:13 PM
If you use \ for division you will get the result as an integer (whole number). Use '/'
So: 100\102 is 0, but 100/102 is 0.98

bostjank
06-11-2003, 03:15 PM
Is it me, or is your formula for percentages a wee bit strange?

When I want percentages, I use (compared value / base value) * 100

Running Bear
06-11-2003, 03:24 PM
Thanks a bunch, that's worked!

Running Bear
06-11-2003, 03:26 PM
Yar it is! I've changed it round, I'm not responsible for it. I inherited it.... no doubt you're thinking - right that's what they all say!

Cheers Al