jquery - How to remove the last comma in JavaScript, while formatting currency? -



jquery - How to remove the last comma in JavaScript, while formatting currency? -

i have code :

function money_format(number) { //if (isnan(number)) homecoming ""; var str = new string(number); var result = "" , len = str.length; for(var i=len-1;i>=0;i--) { if ((i+1)%3 == 0 && i+1!= len) { result += ","; } result += str.charat(len-1-i); } homecoming result; }

event:

$("#number").keyup(function() { var tot = 0; tot = $(this).val().substr(0).replace(/\./g,'') $(this).val(money_format(tot)); $("#msg").html(tot); });

se jsfiddle :http://jsfiddle.net/bx5bu3j0/

how remove lastly coma??

like : 1.000.000,01

if utilize string replace stops when reaches non-digit can add together commas string decimal-

function addcommas(n){ var rx= /(\d+)(\d{3})/; homecoming string(n).replace(/^\d+/, function(w){ while(rx.test(w)){ w= w.replace(rx, '$1,$2'); } homecoming w; }); } var n=123456789.091; addcommas(n) /* returned value: (string) 123,456,789.091 */

javascript jquery

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -