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.

Home Page:https://whoisandy.github.io/react-rangeslider/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The problem with numbers with decimals

svrostislav opened this issue · 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

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 thank you
I had resolved this issue on our project exactly in this way.

Maybe someone may resolve it under the hood.