How To Add Commas To Numbers Without Rails Or ActiveSupport

Posted by Weston Ganger

February 28, 2017

Heres a quick technique to add commas to a numbers in Ruby when you don’t have access to Rails or ActiveSupport

num = 123456789
num.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse

Related External Links:

Posted in Rails and Tagged with ruby

Recommended Posts