Rails

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 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts