0

I am trying to convert the output of the range from the input field to a Currency Format in Js. The Numbers are displaying correctly but I will like to convert it to Number Format on the output

const slider = document.getElementById("idc");
const value = document.getElementById("idk");
value.textContent = slider.value;
slider.oninput = function() {
  value.textContent = this.value;
}
<input type="range" name="range" min="0" max="5000000" id="idc" step="1000" value="0">
<h4>$</h4>
<h4 id="idk">0</h4>
j08691
  • 204,283
  • 31
  • 260
  • 272
Nelson
  • 5
  • 2
  • Does this answer your question? [How to format numbers as currency strings](https://stackoverflow.com/questions/149055/how-to-format-numbers-as-currency-strings) – 0stone0 Jun 27 '22 at 15:49

1 Answers1

0

Does this work for you?

const slider = document.getElementById("idc");
const value = document.getElementById("idk");
value.textContent = slider.value;
slider.oninput = function() {
  value.textContent = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(this.value);
}
<input type="range" name="range" min="0" max="5000000" id="idc" step="1000" value="0">
<h4>$</h4>
<h4 id="idk">0</h4>
Coskun Ozogul
  • 2,389
  • 1
  • 20
  • 32