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 ($Section1 79Amount+$ BonusDepAm ount+$fyea rvalue, 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($Section179 Amount+$Bo nusDepAmou nt+$fyearv alue, 2, '.', ',')/number_format($Aircra ftCost, 2, '.', ','))*100;
echo $str.='<tr class="style14" height=30 style4><td colspan=2>Total Deductions</td><td colspan=2>$'.number_format ($Section1 79Amount+$ BonusDepAm ount+$fyea rvalue, 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?
echo $str.='<tr class="style14" height=30 style4><td colspan=2>Total Deductions:</td><td colspan=2>$'.number_format
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($Section179
echo $str.='<tr class="style14" height=30 style4><td colspan=2>Total Deductions</td><td colspan=2>$'.number_format
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?
Must be the commas you are adding to the formatting. Calculate the $percent without the commas.
ASKER
hello, thanks for the reply. can you give me an example based on what I provided?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!