From: "mame (Yusuke Endoh)" Date: 2012-03-25T15:59:36+09:00 Subject: [ruby-core:43627] [ruby-trunk - Feature #4786][Assigned] RCR new Feature: Numeric#grouped Issue #4786 has been updated by mame (Yusuke Endoh). Status changed from Open to Assigned Assignee set to mame (Yusuke Endoh) ---------------------------------------- Feature #4786: RCR new Feature: Numeric#grouped https://bugs.ruby-lang.org/issues/4786#change-25127 Author: rogerdpack (Roger Pack) Status: Assigned Priority: Normal Assignee: mame (Yusuke Endoh) Category: Target version: Hello all. As discussed in http://www.ruby-forum.com/topic/1060694#new with apparently no objection, this is a request for an easy way to get comma separated string values from numeric types. 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" class Numeric def separate(sep=",") self.to_s.reverse.scan(/(?:\d*\.)?\d{1,3}-?/).join(sep).reverse end end Another option would be to support this extended printf syntax: >> "%'d" % 12345678 => 12,345,678 Though I'd lean toward the former. Feedback? Thanks. -roger- -- http://bugs.ruby-lang.org/