0

My slider words perfectly how I want, but how to get it to show commas in the output numbers?

$('input[type="range"]').rangeslider({
  polyfill: false
});
$('#range').on("input", function() {
  $('.output1').val("$" + parseFloat(this.value * 0.0002).toFixed(2));
  $('.output2').val("$" + parseFloat(this.value * 5.01).toFixed(2));
  $('.output3').val("$" + parseFloat(this.value * 0.03).toFixed(2));
  $('.output4').val("$" + parseFloat(this.value * 7.5).toFixed(2));
  $('.output5').val("$" + parseFloat(this.value * 11.75).toFixed(2));
  $('.output6').val(+parseFloat(this.value * 1).toFixed(2));
}).trigger("change");
<link href="https://rangeslider.js.org/assets/rangeslider.js/dist/rangeslider.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rangeslider.js.org/assets/rangeslider.js/dist/rangeslider.min.js"></script>

<center>
  <h1>
    How much can you save?
  </h1>
  <br>Heaps! How much do you usually eat? Drag the slider below:
</center>
<br>

<input type="range" name="range" id="range" value="100" step="1000" min="0" max="1000000">
<br />
<div>Taco Stands: Cost per <b><output class="output6">0</output></b> tacos<br></div>
<div>TacoTaco <output class="output1">0</output></div>
<div>Los Hermanos Tacos <output class="output2">0</output></div>
<div>Natcho Taco <output class="output3">0</output></div>
<div>Taco Bell <output class="output4">0</output></div>
<div>Chipolte <output class="output5">0</output></div>

View on JSFiddle

showdev
  • 28,454
  • 37
  • 55
  • 73
damann
  • 63
  • 7
  • 1
    Use the function here https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript. https://jsfiddle.net/j08691/0qjp8cms/3/ – j08691 Oct 19 '18 at 19:44
  • Thank you! Thats it exactly. – damann Oct 19 '18 at 19:47
  • 1
    Possible duplicate of [How to print a number with commas as thousands separators in JavaScript](https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript) – Louys Patrice Bessette Oct 19 '18 at 20:12

0 Answers0