blackcell Posted April 3, 2013 Share Posted April 3, 2013 //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 https://forums.phpfreaks.com/topic/276502-xampp-install-large-numbers-calcs-not-working-like-preceding-smaller-ones/ Share on other sites More sharing options...
requinix Posted April 3, 2013 Share Posted April 3, 2013 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 = onand try your code with a percentage of Link to comment https://forums.phpfreaks.com/topic/276502-xampp-install-large-numbers-calcs-not-working-like-preceding-smaller-ones/#findComment-1422735 Share on other sites More sharing options...
blackcell Posted April 4, 2013 Author Share Posted April 4, 2013 I tried error reporting and nothing. Attached is three SS. Anything <= 38 works like it should. 39 starts going crazy. Calculates the correct monthly contribution but not the correct monthly values. Anything >= 40 totally goes wrong. http://progtronics.com/files/38.PNG http://progtronics.com/files/39.PNG http://progtronics.com/files/40.PNG Link to comment https://forums.phpfreaks.com/topic/276502-xampp-install-large-numbers-calcs-not-working-like-preceding-smaller-ones/#findComment-1422903 Share on other sites More sharing options...
requinix Posted April 4, 2013 Share Posted April 4, 2013 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 https://forums.phpfreaks.com/topic/276502-xampp-install-large-numbers-calcs-not-working-like-preceding-smaller-ones/#findComment-1422926 Share on other sites More sharing options...
blackcell Posted April 5, 2013 Author Share Posted April 5, 2013 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 https://forums.phpfreaks.com/topic/276502-xampp-install-large-numbers-calcs-not-working-like-preceding-smaller-ones/#findComment-1423071 Share on other sites More sharing options...
blackcell Posted April 5, 2013 Author Share Posted April 5, 2013 I figured the problem resided in the initial calculations since the shift from 39 to 40 causes an overall contribution issue before even entering the loop. Link to comment https://forums.phpfreaks.com/topic/276502-xampp-install-large-numbers-calcs-not-working-like-preceding-smaller-ones/#findComment-1423072 Share on other sites More sharing options...
requinix Posted April 5, 2013 Share Posted April 5, 2013 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 https://forums.phpfreaks.com/topic/276502-xampp-install-large-numbers-calcs-not-working-like-preceding-smaller-ones/#findComment-1423123 Share on other sites More sharing options...
blackcell Posted April 8, 2013 Author Share Posted April 8, 2013 <?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 https://forums.phpfreaks.com/topic/276502-xampp-install-large-numbers-calcs-not-working-like-preceding-smaller-ones/#findComment-1423512 Share on other sites More sharing options...
blackcell Posted April 12, 2013 Author Share Posted April 12, 2013 So is this just some crazy ghost issue? Link to comment https://forums.phpfreaks.com/topic/276502-xampp-install-large-numbers-calcs-not-working-like-preceding-smaller-ones/#findComment-1424353 Share on other sites More sharing options...
mac_gyver Posted April 12, 2013 Share Posted April 12, 2013 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 https://forums.phpfreaks.com/topic/276502-xampp-install-large-numbers-calcs-not-working-like-preceding-smaller-ones/#findComment-1424366 Share on other sites More sharing options...
blackcell Posted April 12, 2013 Author Share Posted April 12, 2013 Yep. That was it. Thanks max_gyver. I've been out of coding for about half a year now so things are a bit rusty. Link to comment https://forums.phpfreaks.com/topic/276502-xampp-install-large-numbers-calcs-not-working-like-preceding-smaller-ones/#findComment-1424372 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.