Page 1 of 1

Rounding a number up

Posted: Fri Feb 25, 2005 10:32 am
by anthony88guy
I need to be able to round a number up. I looked at the round() function, but is it possible to round it up.

i.e. 3.1 -> 4 , 3.9-> 4

Posted: Fri Feb 25, 2005 10:36 am
by Wayne
ceil()

Posted: Fri Feb 25, 2005 10:50 am
by anthony88guy
ok, i have a problem

Code: Select all

<?
$attackgold = $_POST&#1111;'attackgold'];
$defencegold = $_POST&#1111;'defencegold'];
$menuattack = $_POST&#1111;'attack'];
$menudefence = $_POST&#1111;'defence'];
$attackweapons = $attackgold/$attack;
$defenceweapons = $defencegold/$defence;

echo "<p><strong><font size="6">UNDER CONSTRUCTION</font></strong></p>"

if ($attackweapons > 0)&#123;
echo "ceil($attackweapons)";
&#125;else &#123;"";
&#125;

if ($defenceweapons > 0) &#123;
echo "ceil(defenceweapons)";
&#125;else &#123;"";
&#125;

?>
this is the error i get: Parse error: parse error, unexpected T_IF, expecting ',' or ';' in /home/nokiddin/public_html/bankingcalc2.php on line 27

any ideas?

Posted: Fri Feb 25, 2005 10:56 am
by feyd
your first echo is missing a semicolon.

Posted: Fri Feb 25, 2005 10:57 am
by Wayne

Code: Select all

<? 
$attackgold = $_POST&#1111;'attackgold']; 
$defencegold = $_POST&#1111;'defencegold']; 
$menuattack = $_POST&#1111;'attack']; 
$menudefence = $_POST&#1111;'defence']; 
$attackweapons = $attackgold/$attack; 
$defenceweapons = $defencegold/$defence; 

echo "<p><strong><font size="6">UNDER CONSTRUCTION</font></strong></p>" 

if ($attackweapons > 0)&#123; 
echo ceil($attackweapons); 
&#125;else &#123;
echo""; 
&#125; 

if ($defenceweapons > 0) &#123; 
echo ceil(defenceweapons); 
&#125;else &#123;
echo ""; 
&#125; 

?>

Posted: Fri Feb 25, 2005 11:27 am
by anthony88guy

Code: Select all

<?
$attackgold = $_POST&#1111;'attackgold'];
$defencegold = $_POST&#1111;'defencegold'];
$menuattack = $_POST&#1111;'attack'];
$menudefence = $_POST&#1111;'defence'];

if ($attackgold = 0)&#123;
echo "";
&#125;else&#123;
$attackweapons = $attackgold/$attack;
echo "ceil ($attackweapons)";
&#125;


if ($defencegold = 0)&#123;
echo "";
&#125;else&#123;
$defenceweapons = $defencegold/$defence;
echo "ceil ($defenceweapons)";
&#125;

echo "<p><strong><font size="6">UNDER CONSTRUCTION</font></strong></p>";
?>
this is the output: ceil (0)ceil (0)

i am looking for numbers, you can visit the site at http://nokidding.websiteallies.com/bankingcalc.html , check the bottom part, thats the one i am having trouble with.

Posted: Fri Feb 25, 2005 11:29 am
by anthony88guy
when I type nothing into the gold field i get this error,

Warning: Division by zero in /home/nokiddin/public_html/bankingcalc2.php on line 26
ceil ()
Warning: Division by zero in /home/nokiddin/public_html/bankingcalc2.php on line 34
ceil ()

Posted: Fri Feb 25, 2005 11:32 am
by feyd
your code is always setting $attackgold and $defencegold to zero. If $attack or $defence are zero, you will get a divide by zero error/warning..

Posted: Fri Feb 25, 2005 2:41 pm
by anthony88guy
new code

Code: Select all

<?
$attackgold = $_POST&#1111;'attackgold'];
$defencegold = $_POST&#1111;'defencegold'];
$menuattack = $_POST&#1111;'attack'];
$menudefence = $_POST&#1111;'defence'];

if ($attackgold != 0)&#123;
$attackweapons = $attackgold/$attack;
echo "ceil ($attackweapons)";
&#125;else&#123;
echo "";
&#125;


if ($defencegold != 0)&#123;
$defenceweapons = $defencegold/$defence;
echo "ceil ($defenceweapons)";
&#125;else&#123;
echo "";
&#125;

echo "<p><strong><font size="6">UNDER CONSTRUCTION</font></strong></p>";
?>
this code now works, although when it outputs the numbers it doesnt round up, it says ceil(1.77777) or something. Do i have the proper syntax?

Posted: Fri Feb 25, 2005 2:44 pm
by smpdawg
Don't echo the ceil function inside " ". Double quotes are for displaying string literals, you are trying to output the value of a function.

Wrong

Code: Select all

echo "ceil ($defenceweapons)";
Right

Code: Select all

echo ceil ($defenceweapons);

Posted: Fri Feb 25, 2005 5:16 pm
by anthony88guy
thxs guys i got it all to work :)