otuatail Posted August 18, 2015 Share Posted August 18, 2015 (edited) Money in Money Out Balance £101.84 £10.00 £91.84 £1.05 £90.79 £1.96 £88.83 £88.00 £0.83000000000001 <? // Banking Version 1.0.0 22-07-2015 Desmond O'Toole. require("../secure/SecureFunctions.php"); include ("secure/SecureFunctionsBank.php"); session_start(); Session_Init(); $page = "Libray Selection"; if(!isset($_SESSION["Pk"])) { header('Location: index.php'); exit; } $Pk = $_SESSION["Pk"]; if(KeyCheckX($Pk)== 0) { header('Location: index.php'); exit; } if(isRoguebot($Browser) == 1) exit; $_SESSION["K9"] = isRobot($Browser); if($_SESSION["current_page"] <> $page && $_SESSION['Event_Log'] == "YES") { StoreData($page); mailtoX($page,"Desmonds New Site.",""); } $_SESSION["current_page"] = $page; $filename = filename($_SERVER['PHP_SELF']); $Update = date("D d-M-Y H:i", filectime($filename)); $qBalance = GetBalance(); $row = mysql_fetch_array($qBalance); $Date = $row['EntryDate']; $Value = $row['BalanceValue']; $stamp = strtotime($Date); //$ViewDate = date('D d-M-Y' ,$stamp); $StartDate = date('D d-M-Y' ,$stamp); //$QueryDate = date('d-M-Y' ,$stamp); $qGetAllData = GetAllData($Date); $curValue = $Value; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Pages Home</title> <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <META http-equiv="imagetoolbar" CONTENT="no"> <meta http-equiv="refresh" content="60"> <link rel="stylesheet" href="stylesheets/Library.css" type="text/css"> <link rel="stylesheet" href="stylesheets/LibraryMenu.css" type="text/css"> </head> <body> <div id="PageTitle"> <img src="images/LibraryBanner.jpg" alt=""> </div> <? include('SideMenu.php'); ?> <div id="PageContent"> <form action="menu.php" method="post"> <h3>User: <?=greeting()?></h3> <h4><? echo MonthlTakings()?></h4> <div style="width:720px;padding:0px;float:left;"> <div style="width:120px;height:10px;padding:10px;float:left;"><b> Date</b> </div> <div style="width:70px;height:10px;padding:10px;float:left;"><b>Money In</b> </div> <div style="width:70px;height:10px;padding:10px;float:left;"><b>Money Out</b> </div> <div style="width:70px;height:10px;padding:10px;float:left;"><b>Balance</b> </div> <div style="width:70px;height:10px;padding:10px;float:left;"><b>Reason</b> </div> <div style="width:190px;height:10px;padding:10px;float:left;"><b>Comment</b> </div> <div style="width:120px;height:4px;padding:10px;text-align:right;float:left;clear:both"><a href="DataInput.php"><?=$StartDate?></a> </div> <div style="width:70px;height:4px;padding:10px;text-align:right;float:left;"> </div> <div style="width:70px;height:4px;padding:10px;text-align:right;float:left;"> </div> <div style="width:70px;height:4px;padding:10px;text-align:right;float:left;">£<?=$Value?> </div> <div style="width:70px;height:4px;padding:10px;float:left;"> </div> <div style="width:190px;height:4px;padding:10px;float:left;">Brought forward </div> <? while($row = mysql_fetch_array($qGetAllData)) { $stamp = strtotime($row['EntryDate']); $ViewDate = date('D d-M-Y' ,$stamp); $CurDate = date('D d-M-Y' ,time()); $input = '£' . $row['Input']; if($row['Input'] == '0.00') $input = ""; $out = '£' . $row['Output']; if($row['Output'] == '0.00') $out = ""; $reason = GetReasonName($row['Reason']); $colorSelect = ColourPicker($row['Reason'],$row['EntryDate']); $curValue = $Value + $row['Input'] - $row['Output']; $curValue = RestoreDecimal($curValue); $Value = $curValue; $Comment = $row['Comment']; //$ID = TransposeKey($row['Tag']); $ID = $row['Tag']; $x = ""; //if($CurDate == $ViewDate) // $x = "background-color:#cdcccc;"; // background-color:#6495ed; if($colorSelect == "#777777") { ?> <div style="width:120px;height:4px;padding:10px;text-align:right;float:left;text-color:green;clear:both"><?=$ViewDate?></div> <? } else { ?> <div style="width:120px;height:4px;padding:10px;text-align:right;float:left;text-color:green;clear:both"><a href="StatmentEntry.php?ID=<?=$ID?>"><?=$ViewDate?></a></div> <? } ?> <div style="width:70px;height:4px;padding:10px;color:<?=$colorSelect?>;<?=$x?>text-align:right;float:left;"><?=$input?> </div> <div style="width:70px;height:4px;padding:10px;color:<?=$colorSelect?>;<?=$x?>text-align:right;float:left;"><?=$out?> </div> <div style="width:70px;height:4px;padding:10px;color:<?=$colorSelect?>;<?=$x?>text-align:right;float:left;">£<?=$curValue?> </div> <div style="width:70px;height:4px;padding:10px;color:<?=$colorSelect?>;<?=$x?>float:left;"><?=$reason?> </div> <div style="width:190px;height:4px;padding:10px;color:<?=$colorSelect?>;<?=$x?>float:left;"><?=$Comment?> </div> <? } ?> <div style="width:70px;height:1px;padding:10px;float:left;clear:both"> </div> </div> <div style="width:670px;height:50px;padding:0px;float:left;"> <input class="MyButton"type="submit" name="direction" value="Main Menu"> <br> </div> </form> </div> </body> </html> Hi I have data from a database table. The table holds simply the date, Money going in, Money going out and a reason fro the transaction. I simply have a rolling balance which is calculated on the fly as the page is created using the data. What I have is this. But all I am doing is adding and subtracting. I could understand it if I divided 1/3 Edited August 18, 2015 by otuatail Quote Link to comment Share on other sites More sharing options...
requinix Posted August 18, 2015 Share Posted August 18, 2015 Floating-point arithmetic Round your calculations but only at the very end. Quote Link to comment Share on other sites More sharing options...
otuatail Posted August 18, 2015 Author Share Posted August 18, 2015 function RestoreDecimal($curValue) // E2007 { $test = explode(".",$curValue); if(strlen($test[1]) == 1) $curValue .= "0"; return $curValue; Sorry forgot I am using a function to make Shure I have to decimal places because some output was £3.5 not £35.50 Quote Link to comment Share on other sites More sharing options...
Barand Posted August 18, 2015 Share Posted August 18, 2015 what is wrong with number_format ? Quote Link to comment Share on other sites More sharing options...
otuatail Posted August 18, 2015 Author Share Posted August 18, 2015 I am not rounding a calculation 5-2 = 3 is not rounding. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted August 18, 2015 Share Posted August 18, 2015 Umm, number_format is for well formatting numbers not just rounding. Rounding will only occur if are reducing a higher precision number to a lower precision number. There is no need for your RestorDecimal function, when number format will do that for you. Quote Link to comment Share on other sites More sharing options...
otuatail Posted August 18, 2015 Author Share Posted August 18, 2015 Thanks Barand that works but still fail to understand how it RestoreDecimal() caused the problem. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted August 18, 2015 Share Posted August 18, 2015 Its not your function that was causing it. Its to do with floating point arithmetic, see the link in requinix reply. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.