how do convert value of "range" to float numbers in JavaScript?

Viewed 215

When I add float numbers in value="3.4567890", it converts to number type 'int'. I don't want it convert to number type 'int'. I want it to be 'number' or type 'float'.

Example:

const rangeValue = document.querySelector('input');
console.log(rangeValue.value);
<input type="range" min="0" max="0" value="3.4567890">

console.log converts to number type int.

1 Answers

The max attribute should be above the value for the value to be retrieved properly. (Right now, your min is the same as your max, at 0)

Set a step attribute to a very low amount, like 0.0000001:

const rangeValue = document.querySelector('input');
console.log(rangeValue.value);
<input type="range" min="0" max="10" step="0.0000001" value="3.4567890">

Related