kendallkamikaze Posted November 26, 2008 Share Posted November 26, 2008 Alright so I own an online game and when you breed animals you get a genetic profile for them...wellllll the genetic profile keeps giving decimals, this is the code we've implimented to try and prevent that, but its not working. We've tried to make it so that if a number it odd, it will add 1 to it to make it even so that we don't end up with a decimal, but i figure getting a code to try and round it would be a lot easier. <?php if ($number1 == 1 or 3 or 5 or 7 or 9 or 11 or 13 or 15 or 17 or 19 or 21 or 23 or 25 or 27 or 29 or 31 or 33 or 35 or 37 or 39 or 41 or 43 or 45 or 47 or 49 or 51 or 53 or 55 or 57 or 59 or 61 or 63 or 65 or 67 or 69 or 71 or 73 or 75 or 77 or 79 or 81 or 83 or 85 or 87 or 89 or 91 or 93 or 95 or 97 or 99) { $number1 + 1; } else { $number1 + 0; } $number1 = $MareLegs + $StallLegs; $FoalLegs= $number1 / 2; echo "$FoalLegs"; ?> we desperately need some help. Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/ Share on other sites More sharing options...
willpower Posted November 26, 2008 Share Posted November 26, 2008 you need to look at the round fucnction http://uk2.php.net/round Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-699858 Share on other sites More sharing options...
seany123 Posted November 26, 2008 Share Posted November 26, 2008 willpowers link is good.... whats the link to this game you own? Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-699863 Share on other sites More sharing options...
kendallkamikaze Posted November 26, 2008 Author Share Posted November 26, 2008 im very new with php, so its kind of kiddish...but its doing decently www.one-stride.net theres a few games out there like it, but we're trying to have more real life based breeding/genetics involved. other games similar to "OS" are www.equintium.com and www.horseland.com Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-699871 Share on other sites More sharing options...
kendallkamikaze Posted November 26, 2008 Author Share Posted November 26, 2008 im really clueless when it comes to php, on that website which appears to be the best coded rounding function that fits well with what i already have? Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-699873 Share on other sites More sharing options...
DarkWater Posted November 27, 2008 Share Posted November 27, 2008 @thread starter: Okay, there's a MUCH MUCH MUCH better way to check for an odd number. In fact, your way made me choke on my coffee. Use this: if ($number1 & 1) { } Just wanted to let you know. =P Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-700047 Share on other sites More sharing options...
kendallkamikaze Posted November 27, 2008 Author Share Posted November 27, 2008 In fact, your way made me choke on my coffee. told you!! Im totally new at this...i bought this game not knowing ANY php at all and i'm stil learning. my co-owner is also learning php too so we're both learning haha Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-700056 Share on other sites More sharing options...
kendallkamikaze Posted November 27, 2008 Author Share Posted November 27, 2008 <?php if ($number1 == 1 or 3 or 5 or 7 or 9 or 11 or 13 or 15 or 17 or 19 or 21 or 23 or 25 or 27 or 29 or 31 or 33 or 35 or 37 or 39 or 41 or 43 or 45 or 47 or 49 or 51 or 53 or 55 or 57 or 59 or 61 or 63 or 65 or 67 or 69 or 71 or 73 or 75 or 77 or 79 or 81 or 83 or 85 or 87 or 89 or 91 or 93 or 95 or 97 or 99) { $number1 & 1; } else { $number1 & 0; } $number1 = $MareTemperament + $StallTemperament; $FoalTemperament= $number1 / 2; echo "$FoalTemperament"; ?> that? Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-700059 Share on other sites More sharing options...
DarkWater Posted November 27, 2008 Share Posted November 27, 2008 No no. $number1 = $MareTemperament + $StallTemperament; if ($number & 1) { $number++; } $FoalTemperament = $number1 / 2; echo $FoalTemperament; Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-700061 Share on other sites More sharing options...
kendallkamikaze Posted November 27, 2008 Author Share Posted November 27, 2008 No no. $number1 = $MareTemperament + $StallTemperament; if ($number & 1) { $number++; } $FoalTemperament = $number1 / 2; echo $FoalTemperament; <?php $number1 = $MareTemperament + $StallTemperament; if ($number & 1) { $number++;} $FoalTemperament = $number1 / 2; echo $FoalTemperament; ?> ??? If thats the code that should be there, it still didnt work DAMN EFFING BREEDING SCRIPT IS THE DEATH OF ME. Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-700062 Share on other sites More sharing options...
DarkWater Posted November 27, 2008 Share Posted November 27, 2008 Are $MareTemperamant and $StallTemperamant set? And try: <?php $FoalTemperament = round(($MareTemperament + $StallTemperament) / 2); ?> Yes, that's the whole code. Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-700064 Share on other sites More sharing options...
kendallkamikaze Posted November 27, 2008 Author Share Posted November 27, 2008 Are $MareTemperamant and $Stal Temperamant set? And try: im not sure excatly what that means, but when you create a horse on the game they are given to you with a set of genetic traits that you cant change, which would be the mare/stalltemp etc. but when you breed you need to combind the two and devide, but since there are odd numbers we keep getting those damn decimals. Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-700065 Share on other sites More sharing options...
kendallkamikaze Posted November 27, 2008 Author Share Posted November 27, 2008 i just tried <?php $FoalTemperament = round(($MareTemperament + $StallTemperament) / 2); echo "$FoalBack"; ?> and then <?php $FoalTemperament = round(($MareTemperament + $StallTemperament) / 2); ?> both of which came up blank. Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-700067 Share on other sites More sharing options...
DarkWater Posted November 27, 2008 Share Posted November 27, 2008 You just tried to echo $FoalBack instead of $FoalTemperament. But my honest guess is that if you had that original if statement (the one to check for odd numbers) messed up so badly, there are more problems with the code. I'd suggest rereading everything and finding things that don't look quite right. Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-700068 Share on other sites More sharing options...
kendallkamikaze Posted November 27, 2008 Author Share Posted November 27, 2008 You just tried to echo $FoalBack instead of $FoalTemperament. But my honest guess is that if you had that original if statement (the one to check for odd numbers) messed up so badly, there are more problems with the code. I'd suggest rereading everything and finding things that don't look quite right. my mistake, even after fixing it, it still didnt work. im not too sure what could be the issue because everything else appears and is acting fine, minus the rounding of the numbers part. hah Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-700071 Share on other sites More sharing options...
kendallkamikaze Posted November 27, 2008 Author Share Posted November 27, 2008 BAHAHAHA I GOT IT. <?php $number1 = $MareNeck + $StallNeck; $FoalNeck=round( $number1 / 2 ); echo "$FoalNeck"; ?> Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-700080 Share on other sites More sharing options...
DarkWater Posted November 27, 2008 Share Posted November 27, 2008 You were giving us the wrong variable names. =P Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-700082 Share on other sites More sharing options...
kendallkamikaze Posted November 27, 2008 Author Share Posted November 27, 2008 You were giving us the wrong variable names. =P no no no, theres 6; head, legs, neck, back, temperment etc. Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-700084 Share on other sites More sharing options...
willpower Posted November 27, 2008 Share Posted November 27, 2008 id suggest posting more complete code so as we can gain a greater understandiong Link to comment https://forums.phpfreaks.com/topic/134425-rounding-decimals-please-help/#findComment-700248 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.