Skip to main content
Post Made Community Wiki by Xyz
Source Link
emont01
  • 101
  • 3

As already mentioned Regex is a tool, a very useful tool IMHO.

Consider this example:

//fomat number using string.replace and regex in javascript
function numberWithCommas(x) {
    return x.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
} 

Just one line to convert for example a number like this 1000000.00 into "1,000,000.00"

Using any other method will be far more complex