How to calculate a percentage using php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Joseph Cobham
    New Member
    • Jan 2012
    • 23

    How to calculate a percentage using php

    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.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    percentage = (# of yes) / (# of responses) * 100

    Comment

    • charles07
      New Member
      • Dec 2011
      • 45

      #3
      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.

      Comment

      Working...