Jump to content

Rounding Decimals PLEASE HELP :(


kendallkamikaze

Recommended Posts

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

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

In fact, your way made me choke on my coffee. :D

 

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

<?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?

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.

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.

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.

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.