SirChick Posted October 3, 2007 Share Posted October 3, 2007 I have a mathematical calculation, and for some reason if i put "1" into the input this is the result i get : 1 Muscle Building sessions giving you a strength gain of 4.99999999999E-5. I have put a script in to cut the decimals so that it'll only go as far as 5 decimals but it still keeps coming up... $DecimalRemovalStrengthresult = number_format($GainTotalStrength,5); $DecimalRemovalStrength = number_format($NewStrength,5); That is what im using to strip the number down so it should only show "4.99999" If i don't put "1" and I put say anything above 1 it'll work fine and only show a figure of 5 decimal places such as 4.99000. So what is actually happening to the number to come up with 4.99999999999E-5 ? Does the value mean infinite number or something else? Quote Link to comment https://forums.phpfreaks.com/topic/71698-maths-result/ Share on other sites More sharing options...
MmmVomit Posted October 3, 2007 Share Posted October 3, 2007 4.999E-5 means (4.999 * 10^(-5)), or 0.00004999. I'm not familiar with the function you're using, but will look into it. What calculations are you doing to arrive at a value for $GainTotalStrength? Quote Link to comment https://forums.phpfreaks.com/topic/71698-maths-result/#findComment-360925 Share on other sites More sharing options...
SirChick Posted October 3, 2007 Author Share Posted October 3, 2007 GainTotalStrength shows how much u gained on top of your total... so like if u previously had 5 and now u have 6 $GainTotalStrength would be 1 Quote Link to comment https://forums.phpfreaks.com/topic/71698-maths-result/#findComment-360936 Share on other sites More sharing options...
MmmVomit Posted October 3, 2007 Share Posted October 3, 2007 Can you post the code that does the calculation? Quote Link to comment https://forums.phpfreaks.com/topic/71698-maths-result/#findComment-360938 Share on other sites More sharing options...
SirChick Posted October 3, 2007 Author Share Posted October 3, 2007 Values that im using: $Percentage1 in this situation is = 0.0001 $StrengthInput = 5 $Happy = 1250 $Strength = $row['Strength']; $StrengthInput = mysql_real_escape_string($_POST['strength']); $Happy = $row['CurrentHappy']; $percentage2 = $Happy * (1 + $percentage1/100); $PercentageAddOn = array(); $PercentageAddOn[] = 1.3232; $PercentageAddOn[] = 3.4221; $PercentageAddOn[] = 1.4221; $PercentageAddOn[] = 1.5; $PercentageAddOn[] = 1.0; $PercentageKey = array_rand($PercentageAddOn); $PercentageAddOn = $PercentageResults[$PercentageKey]; $NewPercentageStrength = $StrengthInput*($PercentageAddOn + $percentage1 + $percentage2); If ($StrengthInput > 0){ $NewStrength = ($Strength) * (1 + $NewPercentageStrength/100); $GainTotalStrength = $NewStrength - $Strength; $DecimalRemovalStrengthresult = number_format($GainTotalStrength,5); $DecimalRemovalStrength = number_format($NewStrength,5); $addstrength = "UPDATE userregistration SET Strength=Strength+'$DecimalRemovalStrength' WHERE UserID='{$_SESSION['Current_User']}'"; $resultresult = mysql_query($addstrength) or die(mysql_error()); If (mysql_affected_rows() == 0) { die('Error ID 0001, contact admin on the Civilian forums immediatly about this error!'); } } Quote Link to comment https://forums.phpfreaks.com/topic/71698-maths-result/#findComment-360940 Share on other sites More sharing options...
MmmVomit Posted October 3, 2007 Share Posted October 3, 2007 Unfortunately, since I don't know what the goal of your program is, I can't really tell which calculations are faulty. There are also some variables in there that I can't tell what they do. I would suggest adding this line of code for debugging echo "<p>Line " . __LINE__ . ": $variable_you_want_to_know_the_value_of</p>"; Adding a bunch of these along the way will give you a lot of intermediate values, which will help you narrow down which calculation is going funky. Quote Link to comment https://forums.phpfreaks.com/topic/71698-maths-result/#findComment-360947 Share on other sites More sharing options...
SirChick Posted October 3, 2007 Author Share Posted October 3, 2007 Hey thanks for the advice... jsut to add its basically a simple increment of a total via a % + what the user input... example: User inputs 5. This is multiplied by 10 Then that 10 + the example "5%" added on to that.... equals for this example 15% Then the total from the field in the database should increase by 15% of what it is. Thats what happens in its simplistic nature but there its meant to be slightly random to avoid user's working out the pattern. Quote Link to comment https://forums.phpfreaks.com/topic/71698-maths-result/#findComment-360978 Share on other sites More sharing options...
MmmVomit Posted October 3, 2007 Share Posted October 3, 2007 Hey thanks for the advice... jsut to add its basically a simple increment of a total via a % + what the user input... example: User inputs 5. This is multiplied by 10 Okay, you get 50. Then that 10 + the example "5%" added on to that.... equals for this example 15% What happened to the 50? Thats what happens in its simplistic nature but there its meant to be slightly random to avoid user's working out the pattern. I'm guessing that this part: $PercentageAddOn = array(); $PercentageAddOn[] = 1.3232; $PercentageAddOn[] = 3.4221; $PercentageAddOn[] = 1.4221; $PercentageAddOn[] = 1.5; $PercentageAddOn[] = 1.0; $PercentageKey = array_rand($PercentageAddOn); $PercentageAddOn = $PercentageResults[$PercentageKey]; is where you are introducing randomness. I think there are better ways to do this. Also, some of your percentage values look funky. $percentage2 = $Happy * (1 + $percentage1/100); /* You wrote $Percentage1 in this situation is = 0.0001 $StrengthInput = 5 $Happy = 1250 Which would mean... $percentage2 = 1250 * (1 + (0.0001 / 100)) $percentage2 = 1250 * (1 + (0.000001)) $percentage2 = 1250 * (1.000001) $percentage2 = 1250.00125 */ I don't know exactly how you're handling percentages in your code, but this doesn't seem right any way I look at it. Quote Link to comment https://forums.phpfreaks.com/topic/71698-maths-result/#findComment-361001 Share on other sites More sharing options...
SirChick Posted October 3, 2007 Author Share Posted October 3, 2007 Crap... did a typo mistake: This is multiplied by 2 to make 10. Yeah i had that exactly written down yet the code is increase by no more than values of 124 to lowest which was 13.42 I don't know how lol It's not the first time I have had code do it's own thing from what i expected it to do.. im sure my logical order of math's is wrong than anything else... ill look into more. Thanks for the help though. Quote Link to comment https://forums.phpfreaks.com/topic/71698-maths-result/#findComment-361020 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.