asp.net.netwebformsrating

Creating a rating system for displaying rating stars in asp.net


I've a values something like this 1.25, 2.50, 3.75 or 4.00:

I can loop on the integers like 1, 2, 3 or 4.

But how I can loop on 3.75?

for (int i = 0; i < 3.75; i++)
{
    // my logic
}

Updated:

The loop I needed as I'm creating a rating system and displaying the rating stars in loop. For example:

If 1.25 then star 1 and quarter (0.25) of star 2. Or if 4.75 then star 4 and last quarter (0.75) of star.

enter image description here 3.75/5

How I can display rating in stars?


Solution

    1. Prepare 2 image files, one has 5 empty-stars and the other has 5 filled-stars, just like: enter image description hereenter image description here

      the 2 images must have same width and height, e.g. 400X70

    2. place the filled-stars overlap on the empty-stars, then crop the filled-stars to a portion of the origin witdh the same as the Rating,

    i.e. the crop div width = image_width / 5 * rating

    e.g. With 3.5 Rating, width = 400 / 5 * 3.5 = 280

      <html>
      <head><title>test</title>
          <style type="text/css">
            .container > * {
                position: absolute;
            }
    
            .container, .crop {
                height: 70px;
            }
    
            .crop {
                overflow: hidden;
            }
        </style>
      </head>
      <body>
        <div class="container">
            <img src="https://i.sstatic.net/yiT2y.png" />
            <!-- the width could be calculated either at server or client side, or define in css -->
            <div class="crop" style="width:280px">
                <img src="https://i.sstatic.net/oTi9e.png" />
            </div>
        </div>
     </body>
     </html>