Jump to content

[SOLVED] finding a percentage


NerdConcepts

Recommended Posts

I've been trying to do this for a while now, and it's to the point I have to figure this out. I have a comm_rating (comment rating). values are 3=positive, 2=neutral, 1=negative. I don't want to put neutral comments since to me those don't show dissatisfaction. I am trying to take all comm_rating with 3 or 1 and fully calculate the percentage of positive feedback. Kind of like how eBay does it. I just can't figure this out.

 

What i have found out...

 

commCount3 and commCount1 are querys to figure out total of 3 or 1 ratings on a certain person.

 

$totalPoints = $commCount3 - $commCount1;

$allPoints = $commCount3 + $commCount1;

$percent = ($totalPoints) / $allPoints * 100;

 

if 3=26 and 1=6 I get a percentage of 58.6206896552

 

for some reason this doesn't seem like it is right. I'm not sure if I doing my math wrong or what. Also I just want the 58 not all the .620...

Link to comment
https://forums.phpfreaks.com/topic/52854-solved-finding-a-percentage/
Share on other sites

You need to include the neutral count in the total to get the true %age of positive responses

 

[pre]

                            $count3

$pos_pcent =    ---------------------------  * 100

                $count3 + $count2 + $count1

[/pre]

Thing is, I'm not trying to even count the neutrals. A neutral is neither good or bad.

 

Thus, EKINdesigns posted something that works perfectly and does return the right percentage.

 

if count3 and count1 = 29

count3 = 23

count1 = 6

rounded percentage is 79% which is right. Thank a bunch.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.