algorithm used to calculate 5 star ratings

前端 未结 14 922
挽巷
挽巷 2021-01-29 17:49

I need to calculate 5-star ratings like the one on Amazon website. I have done enough search to find what is the best algorithm, but I am not able to get a proper answer. For ex

14条回答
  •  攒了一身酷
    2021-01-29 18:45

    a better way to do this,

    rating = (sum_of_rating * 5)/sum_of_max_rating_of_user_count  
    

    example:

    total users rated: 6  
    sum_of_max_rating_of_user_count: 6 x 5 = 30  
    sum_of_rating: 25
    
    rating = (25 * 5) / 30
    

    Done!

提交回复
热议问题