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
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With