0

I've looked at tolocalestring() and it doesn't work.

I'm trying to have it to:

  • 1,000,000
  • 10,000,000
  • ect...

Here is my code:

$(document).ready(function() {
  var number = parseInt($('#test').text(), 10) || 309320350
  number.toLocaleString();

  // Called the function in each second
  var interval = setInterval(function() {
    $('#test').text(number++); // Update the value in paragraph
  }, 1000); // Run for each second
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="test"></p>
brbcoding
  • 13,378
  • 2
  • 37
  • 51

1 Answers1

1

toLocaleString returns a string and leaves the number unchanged. It doesn't "tell" the number how to be formatted later (the number doesn't remember), it does format it. You will need to call it when doing the .text(…) output.

$(document).ready(function() {
  var number = parseInt($('#test').text(), 10) || 309320350

  // Called the function in each second
  var interval = setInterval(function() {
    $('#test').text(number.toLocaleString()); // Update the value in paragraph
    number++;
  }, 1000); // Run for each second
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="test"></p>
Bergi
  • 630,263
  • 148
  • 957
  • 1,375