How To Add Commas To Numbers Without Rails Or ActiveSupport

Posted by Weston Ganger on 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 

Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts