Leser: 23
1 2 3 4 5 6 7 8 9 10
perl -e ' for $j (1000,1_000_000,1_000_000_000) { $i=$j**2; print "\n",$j,": \t",$i,"\t="; printf "%020llu", $i; }' 1000: 1000000 =00000000000001000000 1000000: 1000000000000 =00000000004294967295 1000000000: 1e+18 =00000000004294967295
1 2 3 4 5 6 7 8 9 10
perl -e ' for $j (1000,1_000_000,1_000_000_000) { $i=$j**2; print "\n",$j,": \t",$i,"\t= "; printf "%020.0f", $i; }' 1000: 1000000 = 00000000000001000000 1000000: 1000000000000 = 00000001000000000000 1000000000: 1e+18 = 01000000000000000000
1 2 3 4 5 6 7 8 9 10
perl -e ' for $j (1001,1_000_001,1_000_000_001) { $i=$j**2; print "\n",$j,": \t",$i,"\t="; printf "%020lu", $i; }' 1001: 1002001 =00000000000001002001 1000001: 1000002000001 =00000000004294967295 1000000001: 1.000000002e+18 =00000000004294967295
2009-06-16T10:17:58 LanX-NACHTRAG: Andersherum, wie bekomme ich raus welche Darstellung ein Scalar gerade hat, um printf zu sagen "welche Formatierung er nutzen" soll
2009-06-16T10:30:45 betterworldAber du kannst ja leicht feststellen, ob eine Zahl eine Ganzzahl ist, indem Du sie mit int($zahl) vergleichst.
1 2 3 4 5 6 7 8 9 10 11
perl -e ' ($\,$,)=("\n","\t"); for $j (1001,1_000_001,1_000_000_001,1_000_000_001) { $q=$j**2; print $q,int($q),sprintf("%020u",$q); } ' 1002001 1002001 00000000000001002001 1000002000001 1000002000001 00000000004294967295 1.000000002e+18 1.000000002e+18 00000000004294967295 1.000000002e+18 1.000000002e+18 00000000004294967295
1 2 3 4 5 6
use Math::BigInt; my $n = Math::BigInt->new( 2 ); $n->bpow( 64 ); printf "%040s\n", $n;
1 2 3 4 5 6 7 8 9 10 11 12 13
perl -MMath::BigInt -e ' ($\,$,)=("\n","\t"); for $i (1001,1_000_001,1_000_000_001,1_000_000_000_001) { $j=$i; $q=$j**2; $s=sprintf("%020s",$q); print $q,int($q),$s++,$s; } ' 1002001 1002001 00000000000001002001 00000000000001002002 1000002000001 1000002000001 00000001000002000001 00000001000002000002 1.000000002e+18 1.000000002e+18 000001.000000002e+18 1.000000002e+18 1.000000000002e+24 1.000000000002e+24 001.000000000002e+24 1.000000000002e+24
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
perl -MMath::BigInt -e ' ($\,$,)=("\n","\t"); for $i (1001,1_000_001,1_000_000_001,1_000_000_000_001) { $j=new Math::BigInt "$i"; $s=new Math::BigInt "0"; $q=new Math::BigInt "0"; $q=$j**2; $s=sprintf("%020s",$q); print $q,int($q),$s++,$s; } ' 1002001 1002001 00000000000001002001 00000000000001002002 1000002000001 1000002000001 00000001000002000001 00000001000002000002 1000000002000000001 1000000002000000001 01000000002000000001 01000000002000000002 1000000000002000000000001 1000000000002000000000001 1000000000002000000000001 1000000000002000000000002