Categories
JavaScript Answers

How to replace comma with a dot in the number with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *