whoisandy / react-rangeslider

A lightweight responsive react range slider component.A fast & lightweight react component as a drop in replacement for HTML5 input range slider element.
https://whoisandy.github.io/react-rangeslider/
MIT License
643 stars 237 forks source link

The problem with numbers with decimals #150

Open svrostislav opened 4 years ago

svrostislav commented 4 years ago

If I pass min equals to 1, max equals to 1.8 and step equals to 0.1 I get value 1.7000000000000002 on change

ckainz11 commented 4 years ago

I couldn't fix the problem either, however I have a workaround that you can use. In your onChange function round the value to one decimal point: let roundedValue = Math.round(value * 10) / 10. Also, if you are using the tooltip, there will probably also be this issue where it shows, for example: 1.30000. This can be fixed by using the following format function: const format = value => Math.round(value * 10) / 10 and then passing that to the Slider component

svrostislav commented 4 years ago

@ckainz11 thank you I had resolved this issue on our project exactly in this way.

Maybe someone may resolve it under the hood.