HCSStarRatingView icon indicating copy to clipboard operation
HCSStarRatingView copied to clipboard

Rating is always rounded up

Open dimovskidamjan opened this issue 8 years ago • 4 comments

When using half stars, the rating is aways rounded up like so: For a value of 2.1, the rating view shows 2.5 stars when it should show only 2 stars.

Any properties that handle this? Any way to change that behavior if not?

dimovskidamjan avatar Dec 19 '16 09:12 dimovskidamjan

Hi @dimovskidamjan!

That happens because the value corresponds to what the control is displaying at the moment, and if accurateHalfStars == NO then it will always round up to the next half unit.

For instance, anything > 2.0 & <= 2.5 will always be 2.5 stars because that's what a user expects to happen when scrolling his finger at the beginning of a star.

If you need the actual value (eg. 2.1) you need to set accurateHalfStars = YES, although that will also draw the rating accurately (which is the whole point of that feature).

hsousa avatar Dec 20 '16 08:12 hsousa

I have rating as 3.75. It is always displaying 3.5 and not 4. I tried with accurateHalfStars = YES as well as accurateHalfStars = NO. This is when I am trying to set rating programatically.

For 3.8 rating also it is displaying 3.5 always. May be we should calculate ourself to match half we want to set.

Following function is working for me to round to half number

class func halfRound(floatingNumber: CGFloat) -> CGFloat {
    let denominator = CGFloat(2.0);
    let halfRoundedNumber = (round(floatingNumber * denominator )/denominator);
    
    return halfRoundedNumber
}// func halfRound

chawda avatar Oct 12 '17 07:10 chawda

If accurateHalfStars = YES it should always display the exact portion of the star, without rounding... 🤔

Can you get me a sample snippet or project where this happens? I'd like to debug it and figure out what's happening.

hsousa avatar Oct 12 '17 10:10 hsousa

Yes, accurateHalfStars = YES, and of course allowsHalfStars = YES.

Then i setting from code: float floatRatingValue = (myVal * 100.0) / 100.0; self.starRatingControll.value = floatRatingValue;

i get like 4.75, but 5ts star filled full width......

ChekistNSK avatar Nov 20 '17 21:11 ChekistNSK