awran5 / react-simple-star-rating

A simple react component for adding a star rating to your project.
https://react-simple-star-rating.vercel.app/
MIT License
136 stars 32 forks source link

Rating of less than 5 icons doesn't behave as expected #37

Open jkutianski opened 1 year ago

jkutianski commented 1 year ago

I'm trying to set 3 start, but the value is 5.

image image

In some cases, the stars are not marked

image

laurencepike commented 8 months ago

I'm seeing this as well, seems that while the icon count was reduced the actual rating is still done 1-5. This means that the value returned is actually a fractional value. 2 out of three stars for example corresponds to 2/3 * 5 = 3.33 recurring.

To work around this issue I'm multiplying the rating by 5/9 and then Math.round()

Math.round(rating * 5/9)
mo-hassann commented 1 month ago

First make sure that you added the allowFraction property to your element. When you use 3 starts the value or the rating must be from 0 to 3 so you can convert it using this equation: (value of rating from 0 to 5 / 5) * 3