SV: Super regexp to format numbers
"Terje Kristensen" <[email protected]> Tue, 29 Aug 2006 07:39:31 +0200
| Newsgroups | gmane.comp.lang.perl.fun |
|---|---|
| Message-ID | <0d1901c6cb2d$83a82700$9700a8c0@PC143701003228> |
Here's the golfed version :) ( borrowed from Rick Klements solution to the TPR(0,5b) contest ). s/\B(?=(...)*$)/ /g Terje K p.s. This works on integers only. -----Opprinnelig melding----- Fra: Alexandre Jousset [mailto:[email protected]] Sendt: 28. august 2006 18:14 Til: Fun with Perl Emne: Super regexp to format numbers Hello list, I have a problem that I've solved with some logic and a few lines of code but I'm sure that there is a good regexp that can do the job. So I ask the regexp gurus of this list whether they have a solution. Let's start with this : ---------------------------------------------------- $number = 12345678.1234 $number =~ s/./,/; # change decimal point to French notation spacify($number); # Do the magic print "$number\n"; ---------------------------------------------------- and this should print : 12 345 678,1234 For the moment I have a (too) complicated sub spacify and I would like to simplify it to a regexp. Is this possible ? How ? Of course we can use this to output the number in English notation like '12,345,678.1234', same thing... Any clue ? I'm sure this is an old problem... Regards, -- -- \^/ -- -- -/ O \--------------------------------------- -- -- | |/ \| Alexandre (Midnite) Jousset | -- -- -|___|--------------------------------------- --