"10,000" -> 10000

Rubies:

Besides .gsub(',', '').to_i, what's a good way to un-delimit a big number?

Ideally, it should be the reverse of Rails's number_with_delimiter...

···

--
   Phlip

I would be quite happy with gsub, but if you want another shot on it
you might do
scan(/\d/).join
or
scan( /[+\d-]).join

HTH
Robert

···

On Sat, Jun 13, 2009 at 3:40 PM, Phlip<phlip2005@gmail.com> wrote:

Rubies:

Besides .gsub(',', '').to_i, what's a good way to un-delimit a big number?

Ideally, it should be the reverse of Rails's number_with_delimiter...

--
Phlip

--
Toutes les grandes personnes ont d’abord été des enfants, mais peu
d’entre elles s’en souviennent.

All adults have been children first, but not many remember.

[Antoine de Saint-Exupéry]

Hi,

···

Am Samstag, 13. Jun 2009, 22:40:09 +0900 schrieb Phlip:

Besides .gsub(',', '').to_i, what's a good way to un-delimit a big number?

  str.delete ","

If you like to check the syntax:

  str.gsub /,(\d\d\d)\b/, "\\1"

Bertram

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de

Bertram Scharpf wrote:

  str.delete ","

The near-term winnah! I didn't know .delete() would do them all...

If you like to check the syntax:

It's for Cucumber tables, so if it's in-house, I don't need to annoy my clients. If I could get them to author the tables anyway...

···

--
   Phlip

Robert Dober wrote:

I would be quite happy with gsub, but if you want another shot on it
you might do
scan(/\d/).join
or
scan( /[+\d-]).join

Txbut - imagine if number_with_delimiter magically imbued your string with locale awareness (like the C++ imbue do).

We got anything high-level like that? Some cultures reverse the roles of commas & dots. (I don't rly need locales myself; I'm just annoying the envelop here...)

···

--
   Phlip

Phlip wrote:

Robert Dober wrote:

We got anything high-level like that? Some cultures reverse the roles of
commas
& dots. (I don't rly need locales myself; I'm just annoying the envelop
here...)

I think the real issue here is getting those cultures to use commas and
dots correctly.

/kidding

James

···

--
Posted via http://www.ruby-forum.com/\.