Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: regexp for adding commas to a number

by Deven (Novice)
on Feb 25, 2022 at 04:07 UTC ( [id://11141634]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g;
    
  2. or download this
    s/(
       ^[-+]?            # beginning of number.
    ...
       \G\d{3}           # after the last group, get three digits
       (?=\d)            # but they have to have more digits after them.
    )/$1,/xg;
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (1)
As of 2024-04-24 16:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found