Forum Moderators: coopster

Message Too Old, No Replies

finding a percentage from mysql data

         

celastrina

7:09 pm on Apr 7, 2005 (gmt 0)

10+ Year Member



Hi

I have information in my database that shows as 50:100 and I want to find the percentage of this number so that I can have the value of 50% show up instead of 50:100.

Anyone know how to do this?

celastrina

7:31 pm on Apr 7, 2005 (gmt 0)

10+ Year Member



figured out a way.. probably more difficult than need be... ah well.


$section = $row[value];
$section = list($amount, $totalamount) = explode( ":", $section );
$section = stripslashes($section);

$percent = ($amount/$totalamount) * 100;

$percentage = round($percent);

where $row[value] was 50:100... I sectioned it out so they would be two seperate values and then divided and multiplied to get my percent... then rounded the percent to a non-decimal number. :D

jatar_k

7:48 pm on Apr 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld celastrina,

you beat us to it but that probably would have been very similar to what someone would have answered, glad you figured it out.