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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.