Link to home
Start Free TrialLog in
Avatar of pda4me
pda4me

asked on

PHP Calculation

I have a form based program featured a Total Deductions value that is calculating fine and looks like this:

echo $str.='<tr class="style14" height=30 style4><td colspan=2>Total Deductions:</td><td colspan=2>$'.number_format($Section179Amount+$BonusDepAmount+$fyearvalue, 2, '.', ',').'</td></tr>';

I want to also provide this value in a % of total cost and changed the echo statement to look like this to incorporate a percent value:

$percent = (number_format($Section179Amount+$BonusDepAmount+$fyearvalue, 2, '.', ',')/number_format($AircraftCost, 2, '.', ','))*100;
 echo $str.='<tr class="style14" height=30 style4><td colspan=2>Total Deductions</td><td colspan=2>$'.number_format($Section179Amount+$BonusDepAmount+$fyearvalue, 2, '.', ',').' - '.number_format($percent, 0, '.', ',').'% (of cost)</td></tr>';

I am using the *100 to take the decimal value and convert to %
Example:  400000/500000 = .8
.8 *100 = 80%

This works fine for this calculation but when I change the values to 620000/1000000 the % calculates to 62,000 % ???

What am I doing wrong?
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Must be the commas you are adding to the formatting. Calculate the $percent without the commas.
Avatar of pda4me
pda4me

ASKER

hello, thanks for the reply.  can you give me an example based on what I provided?
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pda4me

ASKER

Thanks!