-2

I have:

<input type="range" id="rating-range-btn" name="ratingrange" min="5" value="5" max="10" step="0.1">

I need to change input value from 1.9 to 2.0 but it shows only 2 without dot and zero

1 Answers1

1

You'll have to trigger a callback function each time the value changes to adjust the value of another element that gets its value from the range because the range value (when a whole number is reached) can't be adjusted.

document.getElementById("rating-range-btn").addEventListener("change", function(e){
  // Force the string value of the range to a number and then force the 
  // number to have a single decimal
  output.textContent = parseFloat(this.value).toFixed(1);
});
<input type="range" id="rating-range-btn" name="ratingrange" min="5" value="5" max="10" step="0.1">
<div id="output">5.0</div>
Scott Marcus
  • 64,069
  • 6
  • 49
  • 71