Thread tausenderpunkt in zahl einfügen (18 answers)
Opened by Froschpopo at 2005-07-31 15:36

Taulmarill
 2005-08-01 15:07
#56866 #56866
User since
2004-02-19
1750 Artikel
BenutzerIn

user image
ähm, also entweder hab ich mich hier komplett verhauen, oder die regexe von strat und crian funktionieren nicht (richtig), code:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use warnings;
use strict;

my @numb3rs = qw/1024 16777215 3,1415926 42 759092417205229390873,8763617/;

for my $num ( @numb3rs ) {
print "number: $num\n";
my $regexed = $num;
$regexed =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1./g;
print "perlfaq: $regexed\n";
$regexed = $num;
$regexed =~ s/(\d+)(\d{3})/$1.$2/;
print "strat: $regexed\n";
$regexed = $num;
$regexed =~ s/(\d\d\d)(?=\d)(?!\d*,)/$1./g;
print "crian: $regexed\n";
} continue {
print '=' x 75, "\n"
}

ausgabe:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
peters@ronin:~> perl test.pl
Possible attempt to separate words with commas at test.pl line 4.
number: 1024
perlfaq: 1.024
strat: 1.024
crian: 102.4
===========================================================================
number: 16777215
perlfaq: 16.777.215
strat: 16777.215
crian: 167.772.15
===========================================================================
number: 3,1415926
perlfaq: 3,1415926
strat: 3,1415.926
crian: 3,141.592.6
===========================================================================
number: 42
perlfaq: 42
strat: 42
crian: 42
===========================================================================
number: 759092417205229390873,8763617
perlfaq: 759.092.417.205.229.390.873,8763617
strat: 759092417205229390.873,8763617
crian: 759092417205229390873,876.361.7
===========================================================================
$_=unpack"B*",~pack"H*",$_ and y&1|0& |#&&print"$_\n"for@.=qw BFA2F7C39139F45F78
0A28104594444504400 0A2F107D54447DE7800 0A2110453444450500 73CF1045138445F4800 0
F3EF2044E3D17DE 8A08A0451412411 F3CF207DF41C79E 820A20451412414 83E93C4513D17D2B

View full thread tausenderpunkt in zahl einfügen