You are here: Re: Ok, why is this happening... « PHP « IT news, forums, messages
Re: Ok, why is this happening...

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация