By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,944 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

How to calculate a percentage using php

P: 23
Hello,

I am having some problems calculating a percentage of a number using php.

For example if i have a questionnaire that users answer on my site and the number of answers is tabulated to be 2662 and i want to calculate the percentage of yes answers from no how do i go about it?

P.S i also know how to get the number of yes and no but i don't know how to calculate the percentage of yes and no.


Any help would be appreciated thank you.
Thank you.
Jan 18 '12 #1

✓ answered by charles07

hi Joseph

calculating percentage is a coomon formula, there is nothing special in PHP

for e.g.

total no. of answers = 2662
correct answers = 2000

so % of total answers (2000 / 2662) * 100 = 75%

hope this helped.

Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,349
percentage = (# of yes) / (# of responses) * 100
Jan 18 '12 #2

P: 45
hi Joseph

calculating percentage is a coomon formula, there is nothing special in PHP

for e.g.

total no. of answers = 2662
correct answers = 2000

so % of total answers (2000 / 2662) * 100 = 75%

hope this helped.
Jan 20 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.