如何使用部分星星实施5星级率系统? [英] How to implement 5 stars Rate System with part of stars?

查看:72
本文介绍了如何使用部分星星实施5星级率系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何实施5星评分系统与部分星级



我用过这个:

How to implement 5 stars Rate System with part of stars

I used this :

Rated.CurrentRating = int value



我可以输入整数值,如1,2,3,4,5但是如何但是2.5

CurrentRating 取整数值而不是double !


I can put integer value like 1,2,3,4,5 but how to but 2.5
CurrentRating takes integer value not double!

推荐答案

我会将结果四舍五入,比如星星的1/4或星的1/2。让我们考虑第二个更简单的选择。您将获得双精度等级,乘以2,然后舍入为整数。它会给你一个整数评级,表示半星在评级值中的含义。



完成后,你需要显示所有填充的恒星(整数值为10)或0到4个完全填充的恒星,然后是0到1个半满的恒星。因此,您只需要3种不同的字形:1)完全填充的恒星,2)半满的恒星,3)未填充的恒星。结合它们来显示结果。



同样,你可以在单星的任何部分表达它。例如,在1/4的情况下,您将需要5个字形:空星,1 / 4,1 / 2,3 / 4和1(完全填充)星。用四分之一星表示的整数等级将通过乘以4并舍入为整数从浮点等级获得。等等...



这不是一个简单的想法吗?






注意你应该精确地舍入到整数,而不是削减小数部分,如果你只是转换为整数就可能发生。使用 Math.Round

I would round up the result by, say 1/4 of star or 1/2 of star. Let's consider the second, simpler option. You take you double-precision rating, multiply by 2, and then round to integer. It will give you an integer rating, expressing how much half-stars are in the rating value.

When this is done, you need to show either all filled stars (integer value of 10) or 0 to 4 fully-filled stars followed by 0 to 1 half-filled stars. Therefore you will need just 3 different glyphs: 1) fully-filled star, 2) half-filled star, 3) not-filled star. Combine them to show the result.

Likewise, you can express it in any fraction of the single star. For example, in case of 1/4, you will need 5 glyphs: empty star, 1/4, 1/2, 3/4 and 1 (fully filled) star. You integer rating expressed in quarter-stars will be obtained from floating-point rating by multiplying by 4 and rounding to integer. And so on…

Isn't it a simple idea?



Note that you should precisely round to integer, not to cut fractional part which could happen if you just typecast to integer. Use Math.Round:
double fractionalRating = //...
byte integerRating = // in half-stars, value 0 to 10:
   (byte)Math.Round(fractionalRating * 2);





比如说,2.9应该给你6个整数等级(半星数)(显然是3个完全填充的星),而不是5个(2.5星),因为它会只是施法才发生。



-SA


这篇关于如何使用部分星星实施5星级率系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆