[PHP] math - somethings wrong

2001-05-16 Thread Michael Roark

$percentage=(($target_score/($fleet_score+$total_score))*.4)*100;
 if ($percentage = 10) {
$percentage='10';
$capped=$target_roids*($percentage/100);
} else {

$capped=$target_roids*($percentage/100);

}
}


I get different results on a calculator than I don with this script. This is the order 
i do things on the calc:

($fleet_score+$total_score))*.4)

then the 

(($target_score/

then the 

*100

i think my problem is some where in the if ($percent =10) that port is there because 
regardless of the results returned by the formula the percentage can never be larger 
than 10



Re: [PHP] math - somethings wrong

2001-05-16 Thread Nathan Cook

There are some comments below.  I hope this will point you in the right
direction.

/* Yours :: $percentage=(($target_score/($fleet_score+$total_score))*.4)*100; */

/* From looking at the math you do on the calculator you may want to try this
instead. */
$percentage=(($target_score/($fleet_score+$total_score)*.4))*100;

/* or break it apart */
$divisor = ($fleet_score + $total_score) * .4;
$divide = $target_score / divisor;
$percentage = $divide * 100;

if ($percentage = 10) {
$percentage='10';
$capped=$target_roids*($percentage/100);
// Print the vars to check math! ;-)
print(Percentage: $percentage | Capped: $capped);
} else {
$capped=$target_roids*($percentage/100);
// Print the vars to check math! ;-)
print(Percentage: $percentage | Capped: $capped);
}

Good Luck!
Nathan Cook
[EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]