c# - string.Format("{0:n0}") in javascript -


this question has answer here:

i'm trying find equivalent function to:

string.format("{0:n0}") 

in javascript.

or in different words, have long number 10898502 , want display 10,898,502.

is there easy way ?

thanks,

for pure javascript solution, recommend function below. courtesy of community wiki entry: how can format numbers money in javascript?

number.prototype.formatmoney = function(c, d, t){ var n = this,     c = isnan(c = math.abs(c)) ? 2 : c,      d = d == undefined ? "." : d,      t = t == undefined ? "," : t,      s = n < 0 ? "-" : "",      = parseint(n = math.abs(+n || 0).tofixed(c)) + "",      j = (j = i.length) > 3 ? j % 3 : 0;    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + math.abs(n - i).tofixed(c).slice(2) : ""); };   console.log(     (1000000.94).formatmoney(1, '.', ',')   // 1,000,000.9 ); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -