Sometimes, we want to replace comma with a dot in the number with JavaScript.
In this article, we’ll look at how to replace comma with a dot in the number with JavaScript.
How to replace comma with a dot in the number with JavaScript?
To replace comma with a dot in the number with JavaScript, we use the replace
method.
For instance, we write
const newStr = str.replace(/,/g, ".");
to call replace
on string str
to replace all commas with dots and return the new string.
We use /,/
to match a comma.
The g
flag makes replace
replace all matches.
Conclusion
To replace comma with a dot in the number with JavaScript, we use the replace
method.