"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…

On Sat, Jun 13, 2009 at 3:40 PM, Phlip[email protected] 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

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


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

Robert D. 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 wrote:

Robert D. 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

Bertram S. 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…