I came across an interesting requirement today to format a floating number as currency. In the US and many other countries, currency greater than or equal to 1000 units ($1,000.00) is typically broken up into triads via a comma delimiter. My initial reaction was to use a recursive function, but I glanced at the Rails’ ActiveSupport gem to see how their number_with_delimiter
method performed this same task. I was surprised to learn that this was handled via a clever regular expression.
View at https://coderwall.com/p/uccfpq