javascript: Format a number to display thousands US style (#,###,###,###)

[javascript]
/**
* Format a number to display thousands like in the US -> 1000000 => 1,000,000
* @param number
* @returns
*/
function formatThousands(number) {
return Math.max(0, number).toFixed(0).replace(/(?=(?:d{3})+$)(?!^)/g, ‘,’);
}
[/javascript]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.