quelle Posted December 21, 2010 Share Posted December 21, 2010 Ive got a simple function that's counting percentages of the results, and what I want is when the first line does $variable / 100 - to go on 2 decimals(ex. 0.72142141 what I want is to write 0.72). function postotak(){ $p = $bodovi / 100; $postotak = $p * 100; Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 21, 2010 Share Posted December 21, 2010 round() function? Quote Link to comment Share on other sites More sharing options...
quelle Posted December 21, 2010 Author Share Posted December 21, 2010 the round function goes on an integer as i read 5 minutes ago, but if there is no other way it not a big deal rly ... (for ex. if $score = 60, $p=$score/110, $postotak=$p*100, $postotak = 54%). Btw my function postotak(){ $p = $bodovi / 100; $postotak = $p * 100; $postotak = $postotak + "%"; return $postotak; } It does return nothing why Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 21, 2010 Share Posted December 21, 2010 because $bodovi is not defined in your function. and this should be... $postotak = $postotak . "%"; Quote Link to comment Share on other sites More sharing options...
quelle Posted December 21, 2010 Author Share Posted December 21, 2010 yeah thanks for that $postotak = $postotak . "%"; figured it now. The variable isnt defined but i used global $bodovi outside of function, shouldnt be same ? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 21, 2010 Share Posted December 21, 2010 you must declare global $bodovi; inside the function, but better to just pass it to the function instead of relying on globals. Quote Link to comment Share on other sites More sharing options...
quelle Posted December 21, 2010 Author Share Posted December 21, 2010 hmm lol look at this function postotak($bodovi){ $p = $bodovi / 100; $postotak = $p * 100; $postotak = $postotak . "%"; return $postotak; } Warning: Missing argument 1 for postotak(), called in D:\xampp\htdocs\vjezbe\kviz - seica\rezultati.php on line 35 and defined in D:\xampp\htdocs\vjezbe\kviz - seica\rezultati.php on line 28 - THIS IS THE ERROR I GOT BY PASSING THE VARIABLE TO THE FUNCTION 28th line is the first line of this function Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 21, 2010 Share Posted December 21, 2010 <?php function postotak($input_var){ $p = $input_var / 100; $postotak = $p * 100; $postotak = $postotak . "%"; return $postotak; } echo postotak($bodovi); ?> Quote Link to comment Share on other sites More sharing options...
quelle Posted December 21, 2010 Author Share Posted December 21, 2010 ty Quote Link to comment 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.