Netty Posted October 31, 2006 Share Posted October 31, 2006 [code]91 }92 $percent = round((($rankp-$old)/($max-$old))*100);93 ?>[/code]this is the error i am getting ...[quote]Warning: Division by zero in ...[/quote]Its from a member ranking system ...Thanks alot! Link to comment https://forums.phpfreaks.com/topic/25655-warning-division-by-zero-in/ Share on other sites More sharing options...
bqallover Posted October 31, 2006 Share Posted October 31, 2006 Not sure what to say really :)It would seem the expression ($max-$old) is at some point zero, and thus creating the div. by zero error. Without knowing more about the system (what do those variables represent?) I'd suggest doing a check like [code]if( $max != $old ){ $percent = round((($rankp-$old)/($max-$old))*100);}else{ ... handle the error ...}[/code] Link to comment https://forums.phpfreaks.com/topic/25655-warning-division-by-zero-in/#findComment-117099 Share on other sites More sharing options...
Netty Posted October 31, 2006 Author Share Posted October 31, 2006 [code]$percent = round((($rankp-$old)/($max-$old))*100);[/code]chases this:[code]<?php echo "£".makecomma($fetch->money).""; ?>[/code]the if statement done nothing :(thanks alot for ur help so far hun! Link to comment https://forums.phpfreaks.com/topic/25655-warning-division-by-zero-in/#findComment-117101 Share on other sites More sharing options...
bqallover Posted October 31, 2006 Share Posted October 31, 2006 Hmmmmm. It STILL bombs out with a div by zero error? It shouldn't as far as I can tell. Are you sure that's where the error is coming from? Link to comment https://forums.phpfreaks.com/topic/25655-warning-division-by-zero-in/#findComment-117107 Share on other sites More sharing options...
Netty Posted October 31, 2006 Author Share Posted October 31, 2006 Ahh ...the error is only displayed when i am logged in as Admin/Mod or the very last rank ... Hmm.. Link to comment https://forums.phpfreaks.com/topic/25655-warning-division-by-zero-in/#findComment-117111 Share on other sites More sharing options...
doni49 Posted October 31, 2006 Share Posted October 31, 2006 Have you tried echoing those variables to the screen?echo "<br />Rankp: " . $rankp;echo "<br />Max: " . $max;echo "<br />Old: " . $old;echo "<br />Rankp - Old: " . $rankp-$old;echo "<br />Max - Old: " . $max-$old; Link to comment https://forums.phpfreaks.com/topic/25655-warning-division-by-zero-in/#findComment-117122 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.