[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

"10,000" -> 10000

Phlip

6/13/2009 1:37:00 PM

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
5 Answers

Robert Dober

6/13/2009 2:45:00 PM

0

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...
>
> --
> =A0Phlip
>
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



--=20
Toutes les grandes personnes ont d=92abord =E9t=E9 des enfants, mais peu
d=92entre elles s=92en souviennent.

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

[Antoine de Saint-Exup=E9ry]

Bertram Scharpf

6/13/2009 5:09:00 PM

0

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

Phlip

6/14/2009 3:12:00 AM

0

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

6/14/2009 3:18:00 AM

0

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

James Dinkel

6/15/2009 12:05:00 AM

0

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