Search code examples
jquerynumber-formatting

Add comma to numbers every three digits


How can I format numbers using a comma separator every three digits using jQuery?

For example:

╔═══════════╦═════════════╗
║   Input   ║   Output    ║
╠═══════════╬═════════════╣
║       298 ║         298 ║
║      2984 ║       2,984 ║
║ 297312984 ║ 297,312,984 ║
╚═══════════╩═════════════╝

Solution

  • 2016 Answer:

    Javascript has this function, so no need for Jquery.

    yournumber.toLocaleString("en");