Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For loop problem.... 1

Status
Not open for further replies.

xscape

Programmer
Apr 18, 2001
144
GB
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=&quot;images/star.gif&quot;>

<% 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! :)
 
Hello, xscape.

Perhaps not much to do with asp. See the transformed score achieves what you're looking for :

Transformed_Score=Round(Original_Score*2)/2

Get the idea?

regards - tsuji
 
A brilliant, thanks! That sorts out the score to the nearest .5! I've just managed to sort it out now as a result of that! Just if you're wondering I put an 'if' after the 'For' Loop that checks if there is a .5 on the end. Works a dream! Thanks for your tips!

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top