» Birthday Bundle - Over $400 worth of Envato files for just $20

Calculate percent from value

Posted on August 31, 2008, Filled under PHP,  Bookmark it

Here’s how you can calculate the percent from a value.

<?php
/* Credits: http://www.bitrepository.com */

// example: number of employees in a company's department (Marketing)
$value = '20';
// total employees that company has
$total = '500'; 

$percent = number_format(($value * 100) / $total);

// percent of employees from the Marketing Department.
echo $percent.'%';
?>

Do you wish to receive the latest updates as soon as they are posted? Get our RSS Feed or Subscribe to the Newsletter!

Get our RSS Feed!

Related Posts

2 Replies to "Calculate percent from value"

  1. Hey thanks for that bit of code,nice post.

  2. Good for int’s but not good for floats, cant handle 29.99 etc :(

Leave a Reply


* = required fields

  (will not be published)


XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Note: If you want to post CODE Snippets, please make them postable first!
(e.g. <br /> should be converted to &lt;br /&gt;)