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 9208369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:36:09+00:00 2026-06-18T00:36:09+00:00

I have five star rating and average score. Average score is float number Five

  • 0

I have five star rating and average score.

  1. Average score is float number
  2. Five star rating just 10 section, one star have two half star (so 10 section is five star)

Ex:

Average score is: from 0 - 5 (average = 4.658, or average = 0.256, 0 <= average <= 5)

Five star rating is 10 section: [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]

How to check and set average score to 10 section base on average score?

This is my code, it very long.

            var twofixed = Math.round(average * 100) / 100;           
            twofixed = Math.abs(twofixed);
            var decimal = twofixed - Math.floor(twofixed)

            twofixed = (twofixed + "").split(".");

            if(twofixed[0] == 0)
            {
                if(twofixed[1] == undefined) { average = 0; }
                else
                {
                    if(twofixed[1] <= 99)
                    {
                        average = 0.50;
                    }
                    else
                    {
                        average = 1;
                    }
                }
            }
            else if(twofixed[0] == 1)
            {
                if(twofixed[1] == undefined) { average = 1; }

                else
                {
                    if(twofixed[1] <= 99)
                    {
                        average = 1.50;
                    }
                    else
                    {
                        average = 2;
                    }
                }
            }
            else if(twofixed[0] == 2)
            {
                if(twofixed[1] == undefined) { average = 2; }
                else
                {
                    if(twofixed[1] <= 99)
                    {
                        average = 2.50;
                    }
                    else
                    {
                        average = 3;
                    }
                }
            }
            else if(twofixed[0] == 3)
            {
                if(twofixed[1] == undefined) { average = 3; }
                else
                {
                    if(twofixed[1] <= 99)
                    {
                        average = 3.50;
                    }
                    else
                    {
                        average = 4;
                    }
                }
            }
            else if(twofixed[0] == 4)
            {
                if(twofixed[1] == undefined) { status = 'Great'; average = 4; }
                else
                {
                    if(twofixed[1] <= 99)
                    {
                        average = 4.50;
                    }
                    else
                    {
                        average = 5;
                    }
                }                    
            }
            else if(twofixed[0] == 5)
            {
                if(twofixed[1] == undefined) { average = 5; }
            }

Big thanks to @th3falc0n with small code, I write more than 50 line of code, but you can do with one line of code to solve of my long code.

Thanks everyone to help me, and sorry for unclearly question and bad english

  • 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-06-18T00:36:10+00:00Added an answer on June 18, 2026 at 12:36 am

    I think you just need

    Math.floor(average * 2.0) / 2.0;
    

    This code leaves only x.y from any float number.

    Edit: I made a little mistake. I set it to 0.1 steps so it would make 0.85 to 0.8, that is fixed now (1/2.0) = 0.5 steps. You can use 4.0 for 0.25 steps 10.0 for 0.1 and so on.

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

Sidebar

Related Questions

I have 5 stars system in html/smarty below <ul class=star-rating id={$ID}> <li><a href=# class=one-star></a></li>
I have code to render five star rating base on the rating, I think
I have five buttons on one form that when clicked enables a bool each
I have five masked text box in my form. Two masked text box with
I have five consumers and one producer. The five consumers each output different data,
i have five forms in my c# project. one host an httplistener that i
I have five fields for number input, and each of these fields must be
I have a working star rating system, but If a user has already voted
I have five text boxes that are subclassed views that cycle values from an
I have in database: User: id | name 1 | one 2 | two

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.