Skip to content Skip to sidebar Skip to footer

Comma-formated Numbers In JQuery

I have following function in jQuery to format the number into comma-formatted: function CommaFormattedN(amount) { var delimiter = ','; var i = parseInt(amount); if(i

Solution 1:

You can use Number.toLocaleString() function to format a number into a locale specific format. Note that the output of the function varies with regional settings:

var n = parseInt("-123456789", 10);
console.log(n.toLocaleString())
// returns -123,456,789 on my computer (english-us locale)
// returns -123 456 789 for french locale
// returns -123.456.789 for german locale
// returns -123'456'789 for romansh (???) locale

Solution 2:

  1. There is a bug related to sign. You are using absolute value instead of original one.
  2. Your code seems to work fine, you can try debugging the way you are calling your function.

Here is your working code with minor edit ( sign related ) : http://jsfiddle.net/qcVDc/1/


Post a Comment for "Comma-formated Numbers In JQuery"