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. 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. 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. 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. 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. Link to comment https://forums.phpfreaks.com/topic/257018-the-symbol-on-variables/#findComment-1317551 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.