Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: "Commifying" a number

by Aristotle (Chancellor)
on Dec 10, 2006 at 21:29 UTC ( [id://588941]=note: print w/replies, xml ) Need Help??


in reply to Re^2: "Commifying" a number
in thread "Commifying" a number

that almost works

Nice catch; should have been obvious when I wrote it.

Btw, your lookahead assertion needn’t be quantified: (?=\d) will work exactly as (?=\d+) does, but won’t waste time matching extra digits.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re^4: "Commifying" a number
by Anonymous Monk on Aug 13, 2009 at 14:47 UTC
    Here is a version without using reverse function. sub commify { (my $number = shift) =~ s/\G(-?)(\d{1,3})(?=(?:\d\d\d)+(?:\.|$))/$1$2,/g; return $number; } Manikanthan Velayutham programmed to think BIG
      My earlier post did not appear properly.
      sub commify { (my $number = shift) =~ s/\G([+|-]?)(\d{1,3})(?=(?:\d\d\d)+(?:\.|$ +))/$1$2,/g; return $number; }
      Manikanthan Velayutham

      programmed to think BIG

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://588941]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-03-29 01:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found