...

View Full Version : how to get 5% out of any given number



emuse
07-30-2007, 01:38 AM
Does anyone know the formula in php to get 5% from any given number?
For example: like on my site it shows that lets say I made $300.00 today and I get to keep 5% of that so now I want it to show 5% of 300 which is 60. so I would get to keep $60.00 dollars.

How or what is the code to get 5% of any number in php?

If there are any questions please let me know! Thanks guys!:thumbsup:

bcarl314
07-30-2007, 01:43 AM
Sounds like basic math to me...



$rate = 5.00; //percent
$totalAmount = 300.00

$commission = $totalAmount*($rate/100);
print $commission;

emuse
07-30-2007, 01:48 AM
ok thanks man I freaking had a brain freeze! I went to bed way to late! lol thankx so much!

emuse
07-30-2007, 03:09 AM
ok so now here is my big question. I have tried a lot of things and I cant multiply 0.05 by sales (a number in the database). How would I do that with $row['sales']; in the code?

Here is part of the code:


<?php

$con = mysql_connect("localhost", "root", "blah");
if (!$con)
{
die('Could not connect: ' . mysql_error());

}mysql_select_db("Bus", $con);

$query = "SELECT drivers.last_name, sales.meals, sales.date, sales.bus, sales.sales,
sales.percent ".
"FROM drivers, sales ".
"WHERE drivers.PID = sales.drivers_DID";


$result = mysql_query($query) or die(mysql_error());


// Print out the contents of each row into a table
while($row = mysql_fetch_array($result)){

echo $row['sales'];

}

?>

:confused:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum