title: Convert rating to percentage in 5 star rating system
body: <p>I'm having a 5 star rating system in one of my projects. And i would like to convert each star in to percentage value.</p>
  
  <p>This is my database</p>
  
  <pre><code>star1
  
  star2
  
  star3
  
  star4
  
  star5
  
  tot_stars
  
  average
  </code></pre>
  
  <p>calculation i use to get rating</p>
  
  <pre><code>$cal = ($star1*1 + $star2*2 + $star3*3 + $star4*4 + $star5*5)/$total_stars;
  
  $avg = number_format($cal, 2);
  </code></pre>
  
  <p>What i want to know is what is the math to get each star as a percentage </p>
  
  <p>Example: Yelp.com do this in their website</p>