How to replace comma with a dot in the number (or any replacement)

Leo  picture Leo · Jun 26, 2013 · Viewed 131.3k times · Source

I could not found a solution yet, for replacing , with a dot.

var tt="88,9827";
tt.replace(/,/g, '.')
alert(tt)

//88,9827

i'm trying to replace a comma a dot

thanks in advance

Answer

Dallas picture Dallas · Jun 26, 2013

As replace() creates/returns a new string rather than modifying the original (tt), you need to set the variable (tt) equal to the new string returned from the replace function.

tt = tt.replace(/,/g, '.')

JSFiddle