toolman Posted March 4, 2013 Share Posted March 4, 2013 Hi there, I have a script that works out ratings. Its based on a 1-10 scale with havles, for example 1, 1.5, 2, 2.5 etc. What I want to do is display "stars" instead of actual numbers. Is there a way I can do this using an if statement, for example if the rating is 7.5, display 4 stars? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/275214-display-images-for-rating-system/ Share on other sites More sharing options...
haku Posted March 4, 2013 Share Posted March 4, 2013 (edited) Yes. rating = 7.5; starCount = Math.ceil(Math.ceil(rating) / 2); Edited March 4, 2013 by haku Quote Link to comment https://forums.phpfreaks.com/topic/275214-display-images-for-rating-system/#findComment-1416422 Share on other sites More sharing options...
toolman Posted March 4, 2013 Author Share Posted March 4, 2013 Thanks for the reply. If I wanted to display half a star for the .5, how would I do that? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/275214-display-images-for-rating-system/#findComment-1416429 Share on other sites More sharing options...
haku Posted March 4, 2013 Share Posted March 4, 2013 rating = 7.5; starCount = Math.round(rating) / 2; Quote Link to comment https://forums.phpfreaks.com/topic/275214-display-images-for-rating-system/#findComment-1416467 Share on other sites More sharing options...
Christian F. Posted March 4, 2013 Share Posted March 4, 2013 toolman: What I would do, is to give each half of the star a value of 1, then round off your score to the nearest whole number. Incidentally, that means that you will never display half a star for the .5, seeing as .5 is actually a quarter of a star. If you had 6.5 stars, on the other hand, it would round up to 7 and thus give you three and a half stars. Quote Link to comment https://forums.phpfreaks.com/topic/275214-display-images-for-rating-system/#findComment-1416522 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.