Skip to content

Instantly share code, notes, and snippets.

@Tagliatti
Created December 19, 2014 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tagliatti/5bfdd590f7903f16f701 to your computer and use it in GitHub Desktop.
Save Tagliatti/5bfdd590f7903f16f701 to your computer and use it in GitHub Desktop.
Number Format
function formatNumber(number)
{
number = parseFloat(number);
var number = number.toFixed(2) + '';
var x = number.split('.');
var decimal = x[0];
var value = x.length > 1 ? ',' + x[1] : '';
var pattern = /(\d+)(\d{3})/;
while (pattern.test(decimal)) {
decimal = decimal.replace(pattern, '$1' + '.' + '$2');
}
return decimal + value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment