Re: Ok, why is this happening...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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>';
?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux