Jump to content

Xampp Install - Large numbers calcs not working like preceding smaller ones?


blackcell
Go to solution Solved by mac_gyver,

Recommended Posts

//I am calculating payroll contributions to 401k to give employees a baseline outlook for 20 years to check against their portfolio quarterly reports. It all works until numbers start getting larger. Nothing //ginormous...this is the reason I am at a loss. Is there a setting in php.ini that would be bombing?

Sorry...the code formatting tool is acting dumb.

    $Pay_earnings   = $_REQUEST['Pay_earnings'];
    $Perc_contr     = $_REQUEST['Perc_contr']/100;
    $Perc_emp_contr = $_REQUEST['Perc_emp_contr']/100;
    if($Perc_contr > .08){
        $perc_non_matched = $Perc_contr - .08;
        $Perc_contr = .08;
    }else{
        $non_matched_contri = 0;
    }
    $yourContrib    = number_format(round( (($Pay_earnings*$Perc_contr)+($Pay_earnings*$perc_non_matched)), 2));
    $empContrib     = number_format(round(($Pay_earnings*$Perc_contr)*$Perc_emp_contr,2));
    $totalContrib   = number_format($yourContrib+$empContrib);
    echo "
        <br />
        <table class='Standard' align='center' width='900' border='1'>
                <tr bgcolor='#CCCCCC'>
                    <td colspan='3' align='center'><h1>Per Paycheck Contribution</h1></td>
                </tr>
                <tr>
                    <td width='' align='center'><b><big>Your Contribution</big></b></td>
                    <td width='' align='center'><b><big>Employer Matched Contribution</big></b></td>
                    <td width='' align='center'><b><big>Total Contribution</big></b></td>
                </tr>
                <tr>
                    <td width='' align='center'>$"."$yourContrib</td>
                    <td width='' align='center'>$"."$empContrib</td>
                    <td width='' align='center'>$"."$totalContrib</td>
                </tr>
                <tr bgcolor='#CCCCCC'>
                    <td colspan='3' align='center'><h1>Projection Base(Without Investment Return)</h1></td>
                </tr>
 

This works find until my $Perc_contr rises above 40. Then my $totalContrib toward the bottom does not reflect my $yourContrib in the addition. But the actual TD holding the $yourContrib is fine. I am frikin dumbfounded....

 

Link to comment
Share on other sites

What (example) numbers are you getting and what were you expecting?

 

Also, you should set up your environment for development by making sure you know about errors and warnings as they come up. Open up your php.ini and set

error_reporting = -1
display_errors = on
and try your code with a percentage of
Link to comment
Share on other sites

The "Your Contribution", "Employer Matched Contribution", and "Total Contribution" fields look right. Which is what the code you posted is for.

 

If the problem is with the monthly stuff then how about you post the code for the monthly stuff?

Link to comment
Share on other sites

Of course. Sorry I should have included this. Sorry have a ton going on the past week.

    $totalValue = $Start_value;
    if($Pay_freq == "Bi-Weekly")$incPeriod = 1209600;
    if($Pay_freq == "Weekly")$incPeriod = 604800;
    $payPeriod = 0;
    $year_last = 1900;
    while($payPeriod <= 520){
        $totalValue = $totalValue + $totalContrib;
        $year = date("Y",strtotime($Start_date));
        if($year != $year_last){
            $projection .= "
            <tr bgcolor='#6699FF'>
                <td colspan='3' align='left'><h2><b>$year</b></h2></td>
            </tr>
            ";
            $year_last = $year;
        }
        $projection .= "
            <tr class='Hover'>
                <td colspan='1' align='left'>$Start_date</td>
                <td colspan='2' align='left'>$".round($totalValue,2)."</td>
            </tr>
        ";
        $payPeriod++;
        $Start_date = date("Y-m-d",strtotime($Start_date)+$incPeriod);
    }

Link to comment
Share on other sites

Where's $Start_value coming from? $Pay_freq? The rest of the code?

 

You need to post the whole thing. Posting little pieces here and there just means I have to come back and tell you to keep posting code until you find the right stuff.

Link to comment
Share on other sites


<?php
ini_set("error_reporting","-1");
ini_set("display_errors","on");
$Pay_freq = $_REQUEST['Pay_freq'];
$Start_value = $_REQUEST['Start_value'];
$Start_date = $Start_date_ori = $_REQUEST['Start_date'];
$Pay_earnings = $_REQUEST['Pay_earnings'];
$Perc_contr = $_REQUEST['Perc_contr']/100;
$Perc_emp_contr = $_REQUEST['Perc_emp_contr']/100;
if($Perc_contr > .08){
$perc_non_matched = $Perc_contr - .08;
$Perc_contr = .08;
}else{
$non_matched_contri = 0;
}
$yourContrib = number_format(round( (($Pay_earnings*$Perc_contr)+($Pay_earnings*$perc_non_matched)), 2));
$empContrib = number_format(round(($Pay_earnings*$Perc_contr)*$Perc_emp_contr,2));
$totalContrib = number_format($yourContrib+$empContrib);
$projection = "
<br />
<table class='Standard' align='center' width='900' border='1'>
<tr bgcolor='#CCCCCC'>
<td colspan='3' align='center'><h1>Per Paycheck Contribution</h1></td>
</tr>
<tr>
<td width='' align='center'><b><big>Your Contribution</big></b></td>
<td width='' align='center'><b><big>Employer Matched Contribution</big></b></td>
<td width='' align='center'><b><big>Total Contribution</big></b></td>
</tr>
<tr>
<td width='' align='center'>$"."$yourContrib</td>
<td width='' align='center'>$"."$empContrib</td>
<td width='' align='center'>$"."$totalContrib</td>
</tr>
<tr bgcolor='#CCCCCC'>
<td colspan='3' align='center'><h1>Projection Base(Without Investment Return)</h1></td>
</tr>
";
$totalValue = $Start_value;
if($Pay_freq == "Bi-Weekly")$incPeriod = 1209600;
if($Pay_freq == "Weekly")$incPeriod = 604800;
$payPeriod = 0;
$year_last = 1900;
while($payPeriod <= 520){
$totalValue = $totalValue + $totalContrib;
$year = date("Y",strtotime($Start_date));
if($year != $year_last){
$projection .= "
<tr bgcolor='#6699FF'>
<td colspan='3' align='left'><h2><b>$year</b></h2></td>
</tr>
";
$year_last = $year;
}
$projection .= "
<tr class='Hover'>
<td colspan='1' align='left'>$Start_date</td>
<td colspan='2' align='left'>$".round($totalValue,2)."</td>
</tr>
";
$payPeriod++;
$Start_date = date("Y-m-d",strtotime($Start_date)+$incPeriod);
}

$projection .= "
</table>
";
echo json_encode(array("projection"=>$projection,"date"=>$Start_date_ori));
?>
Link to comment
Share on other sites

  • Solution

an issue that stands out is that you are using number_format() on values, not just for display purposes, but that those formatted numbers are being used in the calculations. when you end up with a number with a comma 1000's separator in it, only the leading number before the comma will be used in the calculations.

 

you should only use number_format() right before you display a value and only to produce the displayed output. the original variable needs to contain the unformatted value.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.