perl/commas.pl: comma-ize numbers greater than 999
This commit is contained in:
parent
23505bf8a5
commit
7da798d8fa
|
@ -0,0 +1,19 @@
|
||||||
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
foreach $arg (0..$#ARGV) {
|
||||||
|
my $num = int($ARGV[$arg]);
|
||||||
|
my $fmt = "", $cnt = 0;
|
||||||
|
|
||||||
|
while($num > 0) {
|
||||||
|
$fmt = ($num % 10) . $fmt;
|
||||||
|
|
||||||
|
if(++$cnt % 3 == 0 and $num >= 10) {
|
||||||
|
$fmt = "," . $fmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
use integer;
|
||||||
|
$num /= 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
print "$fmt\n";
|
||||||
|
}
|
Loading…
Reference in New Issue