|
Posted by "Nadim Attari" on 07/20/05 10:45
Hello,
I've changed the codes. Please run this one to view the results.
The notable change is:
$calculatedGross = $originalNet * (1.000 + ($commissionPct * 0.010));
Regards,
Nadim Attari
Alienworkers.com
<?php
set_time_limit( 0 );
echo '<html>';
echo ' <head><title>Test Rounding Net Premium</title></head>';
echo '<body>';
flush();
echo '<table border="1">';
echo ' <tr>';
echo ' <td>Index</td>';
echo ' <td>Original Net</td>';
echo ' <td>Commission %</td>';
echo ' <td>Calculated Gross</td>';
echo ' <td>Calculated Net</td>';
echo ' <td>Result</td>';
echo ' <td>Comparisson</td>';
echo ' </tr>';
$numberOfFailures = 0;
$index = 0;
for ($originalNet = 10000.000; $originalNet <= 10005.000; $originalNet++)
{
for ($commissionPct = 1.000; $commissionPct <= 20.000; ($commissionPct +=
0.100))
{
$calculatedGross = $originalNet * (1.000 + ($commissionPct * 0.010));
$calculatedNet = $calculatedGross / (1.000 + ($commissionPct *
0.010));
$comparisson = "if ($originalNet !== $calculatedNet) = " . (($originalNet
!== $calculatedNet) ? 'Condition true, it is not equal' : 'Condition false,
it is equal') . "<br>\n";
if ($originalNet !== $calculatedNet)
{
$numberOfFailures++;
$result = 'NEQ';
}
else
{
$result = 'EQ';
}
echo '<tr>';
echo ' <td>' . ++$index . '.</td>';
echo ' <td>' . round($originalNet, 2) . '</td>';
echo ' <td>' . round($commissionPct, 2) . ' %</td>';
echo ' <td>' . round($calculatedGross, 2) . '</td>';
echo ' <td>' . round($calculatedNet, 2) . '</td>';
echo ' <td>' . $result . '</td>';
echo ' <td>' . $comparisson . '</td>';
echo '</tr>';
flush();
}
}
echo '</table>';
echo "<br># of calculations failed to match the original net premium =
$numberOfFailures<br>";
echo '</body>';
echo '</html>';
?>
Navigation:
[Reply to this message]
|