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; Link to comment https://forums.phpfreaks.com/topic/222330-integer-define-s/ Share on other sites More sharing options...
BlueSkyIS Posted December 21, 2010 Share Posted December 21, 2010 round() function? Link to comment https://forums.phpfreaks.com/topic/222330-integer-define-s/#findComment-1150038 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 Link to comment https://forums.phpfreaks.com/topic/222330-integer-define-s/#findComment-1150045 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 . "%"; Link to comment https://forums.phpfreaks.com/topic/222330-integer-define-s/#findComment-1150048 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 ? Link to comment https://forums.phpfreaks.com/topic/222330-integer-define-s/#findComment-1150051 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. Link to comment https://forums.phpfreaks.com/topic/222330-integer-define-s/#findComment-1150053 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 Link to comment https://forums.phpfreaks.com/topic/222330-integer-define-s/#findComment-1150055 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); ?> Link to comment https://forums.phpfreaks.com/topic/222330-integer-define-s/#findComment-1150063 Share on other sites More sharing options...
quelle Posted December 21, 2010 Author Share Posted December 21, 2010 ty Link to comment https://forums.phpfreaks.com/topic/222330-integer-define-s/#findComment-1150064 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.