Hey all,
I've been trying to sort out some code for rating articles. I'll try my best to explain:
Each article can be voted for (1-5; 5 being best). The vote script I wrote does some calculations based on the number of votes and the score which returns the average score (to about 8 decimal places). This is stored in the DB.
The other script that lists the articles puts stars next to each one depending on the average score and displays the exact score next to the stars, but rounded to 3 decimal places (using Round()).
Now, what I'm tring to achieve is half star ratings. At the moment I'm using a for loop, which works fine:
<% For I = 1 to iRoundedScore + 0.5 %>
<img src="images/star.gif">
<% Next %>
By adding the 0.5 to iRoundedScore I get the star rating rounded to the nearest number, eg. 4.123 = 4 stars but 4.789 = 5 stars. Is there any way to round the numbers to the nearest 0.5, so 4.123 = 4 but 4.444 = 4.5 etc..? I just need this for the purposes of the star rating. Then I need the loop to be able to handle half stars, so if it's a score with a .5 it displays the stars then a half star. Any ideas? You all seem to know what you're talking about here, so any help for an ASP newbie would be great! Thanks!
I've been trying to sort out some code for rating articles. I'll try my best to explain:
Each article can be voted for (1-5; 5 being best). The vote script I wrote does some calculations based on the number of votes and the score which returns the average score (to about 8 decimal places). This is stored in the DB.
The other script that lists the articles puts stars next to each one depending on the average score and displays the exact score next to the stars, but rounded to 3 decimal places (using Round()).
Now, what I'm tring to achieve is half star ratings. At the moment I'm using a for loop, which works fine:
<% For I = 1 to iRoundedScore + 0.5 %>
<img src="images/star.gif">
<% Next %>
By adding the 0.5 to iRoundedScore I get the star rating rounded to the nearest number, eg. 4.123 = 4 stars but 4.789 = 5 stars. Is there any way to round the numbers to the nearest 0.5, so 4.123 = 4 but 4.444 = 4.5 etc..? I just need this for the purposes of the star rating. Then I need the loop to be able to handle half stars, so if it's a score with a .5 it displays the stars then a half star. Any ideas? You all seem to know what you're talking about here, so any help for an ASP newbie would be great! Thanks!