Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 1000
Leo Avatar asked Jun 26 '13 12:06

Leo


People also ask

How do you replace a comma with a dot?

Use the replace() method to replace all commas with dots, e.g. const replaced = str1. replace(/,/g, '. '); . The replace method will return a new string with all commas replaced by dots.

How do you replace all commas?

Use the replaceAll() method to replace all commas in a string, e.g. str. replaceAll(',', ' ') . The replaceAll method takes a substring and a replacement as parameter and returns a new string with all matches replaced by the provided replacement.

How do you replace a dot in a string?

Call the replace() method, passing it a regular expression that matches all dots as the first parameter and the replacement character as the second. The replace method will return a new string with all dot characters replaced.


1 Answers

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

like image 125
Dallas Avatar answered Sep 21 '22 21:09

Dallas