Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5974665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:58:28+00:00 2026-05-22T20:58:28+00:00

— link removed — How can I convert the numbers in the above website

  • 0

— link removed —

How can I convert the numbers in the above website into stars using Jquery with a for loop to add however many stars, and a round up, round down function.

I prefer to round using this example:

  • 3.0 if lower than 3.25; this will include 3 full stars, 2 empty stars
  • 3.5 if between 3.25 and 3.75; this will include 3 full stars and 1 half
    star, 1 empty star
  • 4.0 if higherthan 3.75; this will include 4 full stars, 1 empty star
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:58:28+00:00Added an answer on May 22, 2026 at 8:58 pm

    You would need to update your list of ratings to be in a selectable container, and the rading would need to be encapsulated in it’s own selector.

    HTML:

    <ul class="ratings">
      <li>Overall Rating Data (no stars): <span>3.14285714286</span></li>
      <li>Overall Grounds Data (no stars): <span>3.14285714286</span></li>
      <li>Overall Price Data (no stars): <span>3.14285714286</span></li>
      <li>Overall Staff Data (no stars): <span>3</span></li>
      <li>Overall Maintenance Data (no stars): <span>2.85714285714</span></li>
      <li>Overall Noise Data (no stars): <span>3.42857142857</span></li>
      <li>Overall Amenities Data (no stars): <span>3.57142857143</span></li>
      <li>Overall Location Data (no stars): <span>3.28571428571</span></li>
      <li>Overall Parking Data (no stars): <span>3.28571428571</span></li>
      <li>Overall Safety Data (no stars): <span>3</span></li>
    </ul>
    

    JS:

    $(document).ready(function() {
      $('ul.ratings li').each(function() {
        var $el = $(this);
        var rating = $el.find('span').text();
        var $stars = $('<div><div class="ratings-stars"></div><div class="ratings-stars"></div><div class="ratings-stars"></div><div class="ratings-stars"></div><div class="ratings-stars"></div></div>');
        var full_stars = Math.floor(rating);
        var half_star = false;
        var remainder = rating - full_stars;
    
        if(remainder >= 0.25 && remainder <= 0.75) {
          half_star = true;
        } else if(remainder > 0.75) {
          full_stars += 1;
        }   
    
        $stars.find('div:lt('+full_stars+')').addClass('star');
        if(half_star) {
          $stars.find('div:eq('+full_stars+')').addClass('half-star');
        }
    
        $el.find('span').replaceWith($stars);
      });
    });
    

    The CSS I’ll leave up to you.

    EDIT: Updated $stars to use <div /> instead of <span />

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using some of Firefox's specially-defined values for cursor, in particular -moz-zoom-in -moz-zoom-out -moz-grab
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I recently ran against a very interesting site that expresses a very interesting idea
By fixed vector I mean a static list of values, like 1 through 24.
I'm including a local class that requests a file from a remote server. This
My app uses a WebRequest at certain points to get pages from itself. This
This is a follow-up to the question: Should the folders in a solution match
I've got a typical impedance mismatch where the data is stored in a normalized
I've an ASCII file that contains an EM Dash (— or &mdash; in HTML).
I basically have the classic many to many model. A user, an award, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.