PHP - Moved: Integer To Big, Php Math Calculations
This topic has been moved to PHP Math Help.
http://www.phpfreaks.com/forums/index.php?topic=333872.0 Similar TutorialsThis topic has been moved to PHP Math Help. http://www.phpfreaks.com/forums/index.php?topic=328102.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=342385.0 This topic has been moved to PHP Math Help. http://www.phpfreaks.com/forums/index.php?topic=350528.0 This topic has been moved to PHP Math Help. http://www.phpfreaks.com/forums/index.php?topic=310665.0 This topic has been moved to PHP Math Help. http://www.phpfreaks.com/forums/index.php?topic=357542.0 I've written a small ELO class for calculating a players rating for a game league, and for the life of me I don't know why these calculations are coming up wrong. The Class:
Code for testing:
The output i'm getting is as follows, when they should match what i've stated above (as done on paper with a calculator) Player A (1000) has a 9% Chance of winning. Player B (1000) has a 9% chance of winning. Player A's new rating will be 1029 if they win. Player B's new rating will be 1029 if they win. Player A's new rating will be 997 if they lose. Player B's new rating will be 997 if they lose. I've tried re-writing the calculation over and over but just can't get it. I used the Wikipedia page to get my calculations. I've not added K Factor yet but I will be at some point. Hello, I am trying to take the calculations of two variables to create a new data for a new variable. For example.....
LRH_calcLevel($LRH_current, $LRH_bankfull); +/- $LRH_totalDepth = $newVar
Which should translate to -10.43 Ft +/- 40 = $newVar (-29.57) <----- What I want
Instead it is showing up as 10.43 Ft +/- 40 = $newVar (-50.43) <----- How it is displaying which is incorrect
Here is the code I am using. The second function is what I am trying to use to create the new variable data based on the calculations above from the data provide via XML. How can I get this to display correctly?
-Thanks
//Parse Lake Ray Hubbard XML Data $site = simplexml_load_file($LRH_data);{ $LRH_bankfull = '435.5'; $LRH_totalDepth = '40'; $LRH_current = $site->observed->datum[0]->primary; $LRH_vaild = $site->observed->datum[0]->valid; $LRH_updated = DATE("D, M d, g:i a", STRTOTIME($LRH_vaild)); } //Lets calculate the lake depatures from full pool for Lake Ray Hubbard function LRH_calcLevel($LRH_current, $LRH_bankfull) { //Get float values from strings $LRH_current = floatval($LRH_current); $LRH_bankfull = floatval($LRH_bankfull); //Calculate the difference $LRH_calcLevel = $LRH_current - $LRH_bankfull; //Format difference to two decimal places and add 'Ft' $LRH_calcLevelStr = (string) number_format($LRH_calcLevel, 2) . ' Ft'; //If vlaue is positive add a + to beginning if($LRH_calcLevel>0) { $LRH_calcLevelStr = '+'.$LRH_calcLevelStr; } //Return the calculated formatted value return $LRH_calcLevelStr; } ////Lets calculate the lake percentage from full pool for Lake Ray Hubbard $val1 = $LRH_current; $val2 = $LRH_bankfull; $LRH_prec = ( $val1 / $val2) * 100; // 1 digit after the decimal point $LRH_prec = round($LRH_prec, 1); //Lets convert the depature from full pool for Lake Ray Hubbard function LRH_calcDepth($LRH_calcLevelStr, $LRH_totalDepth) { //Get float values from strings $LRH_calcDepthStr = floatval($LRH_calcLevelStr); $LRH_totalDepth = floatval($LRH_totalDepth); //Calculate the difference $LRH_calcDepth = $LRH_calcDepthStr - $LRH_totalDepth; //Format difference to two decimal places and add 'Ft' $LRH_calcDepthStr = (string) number_format($LRH_calcDepth, 2) . ' Ft'; //If vlaue is positive add a + to beginning if($LRH_calcDepth>0) { $LRH_calcDepthStr = '+'.$LRH_calcDepthStr; } //Return the calculated formatted value return $LRH_calcDepthStr; } ////Lets calculate the lake percentage from full pool for Lake Ray Hubbard $val1 = LRH_calcLevel($LRH_current, $LRH_bankfull); $val2 = $LRH_totalDepth; Hi, I have been set a task to use 300000 values from a csv to find the total amount of the values and the averages of the values (mode, mean and median). The csv is set into 2 columns, number and amount with 300000 records for each. I am unsure as to how to use only the values from one of the columns in order to get the results i need. Below is the code I have so far; Code: [Select] $filepath = "testdata.csv"; $file = fopen($filepath, "r") or die("Error opening file"); $i = 0; while(($line = fgetcsv($file)) !== FALSE) { if($i == 0) { $c = 0; foreach($line as $col) { $cols[$c] = $col; $c++; } } else if($i > 0) { $c = 0; foreach($line as $col) { $data[$i][$cols[$c]] = $col; $c++; } } $i++; } //this prints the whole of the data still while (($cols[1])) print_r($data); //this still prints all the data!! while ($data) print_r($cols[1].$data); Am I going about this wrong by using an associative array? Hi I was wondering if somebody could give me some help. I have a form with the following table for users to input <td width="118" style="text-align: left"><input type="text" name="item1cost"></td> <td width="118" style="text-align: left"><input type="text" name="item1Charge"></td> <td width="118" style="text-align: left"><input type="text" name="item1sum""></td> is there a way to have the 3rd field auto populated by calculations made from the data a user puts in the 1st and 2nd field ? The calculation i am actually looking for i can explain easier in excel terms Lets say item1cost is in A2 Item1charge is in B2 Item1sum is in C3
A3 would be the cell i want populating with the calculation of any help would be greatly appreciated thanks
Hello there, I stuck in a silly logic ... I will really appreciate if someone helps me... My Fiscal year starts from 01st April of current year through 31st March of next year, for ex. (01 Apr 2011 to 31st March 2012). I want to put a latefee of 6.25% on total amount, if the payment date is not done on the current fiscal year. Everything depends on the payment date. For example, A bill of $8000 was generated on 01st Apr. 2009 then its 6.25% will be $500 and the customer is paying the same on 30th August 2011, then total years passed is 3. So, the late fee will be 500 * 2 = $1000. i.e. Any bill generated and paid in the current fiscal year (stated above) is free of late fee and after that the above calculation is applicable. Please help, how to do the calculation. A function is really appreciated. Hi guys, I'm working on a project and I can't wrap my head around on a calculation that needs to be done on a multidimensional array. Quick background, it's a hotel benchmarking tool and I need to calculate the market penetration index (MPI). I have an array with 3 main arrays. First 2 are the hotels which are being compared and the last one is the MPI array. Each array contains an array for every month the user selects. Inside THAT array is data that needs to be used for calculations. Here is an example: Code: [Select] Array ( [Competitive set] => Array ( [Sep 11] => Array ( [0] => Array ( [minmonth] => 2011-09-01 [maxmonth] => 2011-09-01 [nrcheck] => 13 [data] => 67.6 ) ) [Oct 11] => Array ( [0] => Array ( [minmonth] => 2011-10-01 [maxmonth] => 2011-10-01 [nrcheck] => 13 [data] => 63.6 ) ) [Nov 11] => Array ( [0] => Array ( [minmonth] => 2011-11-01 [maxmonth] => 2011-11-01 [nrcheck] => 13 [data] => 59.2 ) ) [Dec 11] => Array ( [0] => Array ( [minmonth] => 2011-12-01 [maxmonth] => 2011-12-01 [nrcheck] => 13 [data] => 54.6 ) ) ) [Test] => Array ( [Sep 11] => Array ( [0] => Array ( [minmonth] => 2011-09-01 [maxmonth] => 2011-09-01 [nrcheck] => 89 [data] => 71.5 ) ) [Oct 11] => Array ( [0] => Array ( [minmonth] => 2011-10-01 [maxmonth] => 2011-10-01 [nrcheck] => 89 [data] => 67.0 ) ) [Nov 11] => Array ( [0] => Array ( [minmonth] => 2011-11-01 [maxmonth] => 2011-11-01 [nrcheck] => 91 [data] => 63.1 ) ) [Dec 11] => Array ( [0] => Array ( [minmonth] => 2011-12-01 [maxmonth] => 2011-12-01 [nrcheck] => 89 [data] => 57.5 ) ) ) [MPI] => Array ( [Sep 11] => Array ( [0] => Array ( [minmonth] => 2011-09-01 [maxmonth] => 2011-09-01 [nrcheck] => 89 [data] => 71.5 ) ) [Oct 11] => Array ( [0] => Array ( [minmonth] => 2011-10-01 [maxmonth] => 2011-10-01 [nrcheck] => 89 [data] => 67.0 ) ) [Nov 11] => Array ( [0] => Array ( [minmonth] => 2011-11-01 [maxmonth] => 2011-11-01 [nrcheck] => 91 [data] => 63.1 ) ) [Dec 11] => Array ( [0] => Array ( [minmonth] => 2011-12-01 [maxmonth] => 2011-12-01 [nrcheck] => 89 [data] => 57.5 ) ) ) ) Currently the 'data' for MPI is wrong. That needs to become the data of the first array divided by the data of the second array and multiplied by 100 (percentage). How would I go about doing that? The foreach loops are a bit too big for me on this one. // I am trying to calculate the number of days between dates and have a major problem. When I try the example below, it gives me exactly 201 days, yet the dates have different times, meaning that a full day is impossible. If it matters, I am testing via xampp 1.7.3 with php version 5.3.1 with Windows XP. Can anyone explain what I am doing wrong. Can daylight savings play a role? $frmritedate7116 = strtotime('2010-12-13 23:00'); $frmritedate7156 = strtotime('2010-05-27 00:00'); // $frmritedate7251 = $frmritedate7156 - $frmritedate7116; // // 1274943600-1292310000=-17366400 // 86400 seconds in a day ( 201.00 ) // // // Ok, I made some changes to my code (change in variable names only) and now it doesn't seem to work. Here is the code. <?php if ($_REQUEST['postal'] != "" && $_REQUEST['lbs'] != "") { $postal = $_REQUEST['postal']; $lbs = $_REQUEST['lbs']; $type = $_REQUEST['type']; if ($type == "splist") { $ztype = "cansp_zone" ; $lbstype = "sp"; } else { $ztype = "canmp_zone"; $lbstype = "mp"; } $qP1 = "SELECT * FROM " . $dbprefix . "_canzones WHERE canzone_postal = '$postal' "; $which = $handle_db2; $rsP1 = mysql_query($qP1,$which); if (mysql_num_rows($rsP1) > 0) { $row1 = mysql_fetch_array($rsP1); extract($row1); $prov = trim($canzone_prov); $zone = trim($canzone_zone); $dzone = $ztype.$zone; $dlbs = "can" . $lbstype . "_lbs"; $query = "SELECT $dzone FROM " . $dbprefix . "_can" . $type . " WHERE $dlbs = '$lbs' "; $which = $handle_db2; $result = mysql_query ($query,$which); $row = mysql_fetch_array($result); $dzone = $row[0]; $qP3 = "SELECT * FROM settings WHERE storeid = '$dbprefix' "; $which = $handle_db2; $rsP3 = mysql_query($qP3,$which); $row3 = mysql_fetch_array($rsP3); extract($row3); $taxsetting = trim($taxsetting); $gst = trim($gst); $pst = trim($pst); $hst = trim($hst); $cp_fuelcharge = trim($cp_fuelcharge); $cp_markup = trim($cp_markup); include("./inc/taxcalc.php"); include("./inc/markcalc.php"); ./inc/markcalc.php is as follows: <?php if ($cp_markup != "") { $cp_mark = ($dzone * ($cp_markup / 100)); When I output $cp_mark, it comes out as the same value as $cp_markup Any ideas? Hey, I have this brainstorm whether I should store id's as integers or text? I mean in my database, since my IDs start from like 1319129364 which is a rather large number, I was thinking if it would be better to save it as text? Which case requires less memory ? Hi i'm trying to get out a sub string from multiple pages where i'm using a start point string that looks like this "(integer)" where "integer is different every time. Is there any way I can tell it that its just an integer there so if its "(3)" on one page and "(10)" on another page it will start from the same spot? Ive got a simple function that's counting percentages of the results, and what I want is when the first line does $variable / 100 - to go on 2 decimals(ex. 0.72142141 what I want is to write 0.72). Code: [Select] function postotak(){ $p = $bodovi / 100; $postotak = $p * 100; 0 down vote favorite Hi Guys! I have a method that get's all devices that share a specific ID. Foreach of those device UID's, I am trying to send a APN (Apple Push Notification) using the easyAPN's class. The method that is having the problem is $apns->newMessage($id); It seems to think I am not passing a valid integer for $id. The $id is an array like so Array ( => 1 ) I have also tried passing just the value of the array like so $apns->newMessage($id[0]). No matter what I do.. I keep getting this error... "Notice: TO id was not an integer. 1) Messages_model::send_apns -> File: sendMessage.php (line 28) 2) APNS::queueMessage -> File: messages_model.php (line 195) 3) APNS::_triggerError -> File: class_APNS.php (line 599)" Here is my method... please let me know where I've gone wrong with the $id. function send_apns($data) { include 'apn_classes/class_DbConnect.php'; include 'apn_classes/class_APNS.php'; $message = new Messages_model(); $db = new DbConnect(); $db->show_errors(); $apns = new APNS($db); //get uid's for aid $sql = "SELECT `devices`.`uid` FROM `devices` WHERE `devices`.`aid` = '".$data['target']."'"; //echo $sql; $query = mysql_query($sql); if(mysql_num_rows($query)) { while($uid_data = mysql_fetch_array($query)) $uids[] = array( "uid" => $uid_data['uid'] ); } //make sure there is a uid if(!empty($uids)) { //check the device apn pid foreach($uids as $uid) { $sql = "SELECT `apns_devices`.`pid` FROM `apns_devices` WHERE `apns_devices`.`deviceuid` = '".$uid['uid']."'"; //echo "$sql"; $query = mysql_query($sql); if(mysql_num_rows($query) > 0) { while($pid_data = mysql_fetch_array($query)) { $pids[] = array( "pid" => $pid_data['pid'], ); if(!empty($pids)) { foreach ($pids as $pid) { $id = array($pid['pid']); print_r($id); //Send APN $apns->newMessage($id[0]); $apns->addMessageBadge(128); $apns->addMessageAlert($data['message']); $apns->addMessageSound('chime'); //$apns->addMessageCustom('acme2'); $apns->queueMessage(); $apns->processQueue(); } } } } } } else { echo "Device Does not Exist"; } } I want to round off an integer vaule to 10-6 grd from 52.71666666 to 52716666 0.926888888 to 926888 does anyone know a simple way to do this? So I am trying to take a string value of dollars (posted from a form) and times it by 100 to get the cents Integer value of the dollars. For some reason if I do this with something like 278.53 I end up with 27852. Same concept for 278.59 ends up as 27858. I don't understand why or how to make it work. I've tried many things and nothing has made it work. $price = '278.53'; // posted from the form $cents = $price * 100; // converting to cents. end_result = (int)$cents // This will end up being 27852 not 27853.
Hi there, I am working on a PHP web form and I have a very simple situation I guess, I have a variable named: $MyVal When I do print_r($MyVal); To see whats inside, I get: SimpleXMLElement Object ( [0] => 8.23 ) Now I am assigning this variable into a session variable so that I can do calculations with it. So I assign: $_SESSION['MySesVal'] = $MyVal; But after assigning to session variable, when I do my calculations: $finalValue = $_SESSION['MySesVal'] * 4; I get 0. So is it because the actual $MyVal variable has some XML stuff as: SimpleXMLElement Object ( [0] => 8.23 ) So what is the right way to properly assign $MyVal variable to a session variable to do calculations. Please reply. All comments and feedbacks are always welcome. Thank you! |