From: Nobuyoshi Nakada Date: 2011-05-27T08:17:52+09:00 Subject: [ruby-core:36495] Re: [Ruby 1.9 - Feature #4786][Open] RCR new Feature: Numeric#grouped Hi, At Fri, 27 May 2011 07:22:37 +0900, Roger Pack wrote in [ruby-core:36494]: > Background: > Currently in ruby you can enter large numbers with digit grouping: > a = 1_000_000_000 > > however there is no convenient way to convert from a number back to digit grouping > > Suggestion: > > >> 1_000_000_000.grouped > => "1,000,000,000" If you use round-tripping as the base, the separater should be "_" by default. > class Numeric > def separate(sep=",") > self.e > end > end It makes 12323.separate("xy") "12yx323", which does not seem nice. And not all locales use 3-digits separation. def separate(n, sep="_") to_s.gsub(/\G(?