rorybing Posted February 13, 2012 Share Posted February 13, 2012 Hi, I'm looking through some code I have for setting up a rating system. It was a free open source code, which I need to change to work for my own site. I have it working, but I am now just looking through the code to try and understand it, and for the most part, I do. There is one part I am not familiar with, if somebody could help me please? Values involved; $current_rating = total rate value of votes $count = total number of votes cast Problem I have is the @ symbol here $rating=@number_format($current_rating/$count, 1); Does it format it to decimal places or something like that? It's probably something simple I know, but I am a relative newb. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/257018-the-symbol-on-variables/ Share on other sites More sharing options...
trq Posted February 13, 2012 Share Posted February 13, 2012 The @ symbol is used to suppress errors and should really be avoided and only used when it really is necessary. In this instance, I think they are trying to hide any "divide by zero" error. This could (and should) be better handled by ensuring that $count is bigger than 0 before using it. Quote Link to comment https://forums.phpfreaks.com/topic/257018-the-symbol-on-variables/#findComment-1317545 Share on other sites More sharing options...
rorybing Posted February 13, 2012 Author Share Posted February 13, 2012 Hi, Thanks for the reply. So I should really do this if ($count > 0) { $rating=($current_rating/$count, 1); } Something like that? What would the 1 at the end of that line also mean? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/257018-the-symbol-on-variables/#findComment-1317546 Share on other sites More sharing options...
trq Posted February 13, 2012 Share Posted February 13, 2012 See number_format. Quote Link to comment https://forums.phpfreaks.com/topic/257018-the-symbol-on-variables/#findComment-1317548 Share on other sites More sharing options...
rorybing Posted February 13, 2012 Author Share Posted February 13, 2012 Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/257018-the-symbol-on-variables/#findComment-1317551 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.