I am wanting to display large numbers more nicely with commas. So if the number was say 123456789, it would display 123,456,789. I have looked around but I only found code that just wouldn't work the way I wanted so I was hoping I could find some help here. Also, I hope it is also dynamic, so the commas will change as the number changes.
The number that I want to affect has the id="value".
That should be all, I don't think I am missing anything. So again I want the number with an id="value" to have commas introduced when it's needed. If you need any more information please let me know!
There's a simpler syntax for toLocaleString: Number(x). toLocaleString();
You can use the toLocaleString() method to comma-separate thousands in a number for a given localization, such as 'en-US'. You can also use the Intl. NumberFormatter object to format a number to a specific localization. Lastly, you can also build your own custom function to get the job done.
You can use type="text" and then add commas to the number in the onchange event.
You can use toLocaleString
:
num.toLocaleString('en', {useGrouping:true})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With