perl -e '$_=1234567;s/\./,/;s/(?=(\d\d\d)+(,|\Z))/./g;print'
That doesn't handle 234567 nor 234567.89 too well. :)
My best, based on yours, obviously:
y/./,/;s/\d(?=(\d\d\d)+(,|\Z))/$&./g; # 37, counting the semicolon
Update: Ow, too obviously. \Z is just long-hand for $ ... so slice one off ... and update2 \d\d\d can be shortened to \d{3} for one more:
y/./,/;s/\d(?=(\d{3})+(,|$))/$&./g; # 35, counting the semicolon
... or, to demonstrate ...
sidhekin@blackbox:~$ perl -le 'for (@ARGV) { y/./,/;s/\d(?=(\d{3})+(,|
+$))/$&./g;print }' 1234567.89 234567.89 1234567 234567
1.234.567,89
234.567,89
1.234.567
234.567
sidhekin@blackbox:~$
print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!
|