algorithm used to calculate 5 star ratings

前端 未结 14 1152
挽巷
挽巷 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:26

    with C#

    double rating = (double)(5 * star5 + 4 * star4 + 3 * star3 + 2 * star2 + 1 * star1) / (star1 + star2 + star3 + star4 + star5);
    rating = Math.Round(rating, 1);
    

提交回复
热议问题