Metti valori virgola in numeri - Trucchi CSS

Anonim

Questa funzione presuppone che ciò che le viene sottoposto sia una stringa, con un punto decimale e due posizioni dopo il decimale. Per inserire prima il tuo numero in quel formato, usa questo.

Quindi questa funzione separerà correttamente il numero dalla virgola. Ad esempio, 2345643.00 restituirà 2.345.643.00

function CommaFormatted(amount) ( var delimiter = ","; // replace comma if desired var a = amount.split('.',2) var d = a(1); var i = parseInt(a(0)); if(isNaN(i)) ( return ''; ) var minus = ''; if(i 3) ( var nn = n.substr(n.length-3); a.unshift(nn); n = n.substr(0,n.length-3); ) if(n.length > 0) ( a.unshift(n); ) n = a.join(delimiter); if(d.length < 1) ( amount = n; ) else ( amount = n + '.' + d; ) amount = minus + amount; return amount; )