react-rangeslider icon indicating copy to clipboard operation
react-rangeslider copied to clipboard

The problem with numbers with decimals

Open svrostislav opened this issue 5 years ago • 2 comments

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

svrostislav avatar May 08 '20 09:05 svrostislav

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

ckainz11 avatar Aug 10 '20 14:08 ckainz11

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

Maybe someone may resolve it under the hood.

svrostislav avatar Aug 10 '20 19:08 svrostislav