Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
my @sizes = (40000000000, 3000000000, 200000000, 7000000, 5000, 234);
print get_size($_)."\n" for @sizes;
sub get_size {
local $_ = shift;
if ($_ >= 1024000000) {
$_ /= 1024000000;
$_ = sprintf("%.2f", $_);
return("$_ GIGs");
}
elsif ($_ >= 1024000) {
$_ /= 1024000;
$_ = sprintf("%.2f", $_);
return("$_ MBs");
}
elsif ($_ >= 1024) {
$_ /= 1024;
$_ = sprintf("%.2f", $_);
return("$_ KBs");
}
else {
return("$_ BYTES")
}
}
[b]#!/usr/bin/perl[/b]
@sizes = (40000000000, 3000000000, 200000000, 7000000, 5000, 234);
foreach (@sizes) {
s/^(\d+)(\d{9})$/$1.$2 GIGs/;
s/^(\d+)(\d{6})$/$1.$2 MB/;
s/^(\d+)(\d{3})$/$1.$2 KB/;
s/\.0+( [A-Z]{2,3}[a-z]?)$/$1/;
s/^(\d+)$/$1 BYTES/;
print "$_\n";
}
my @sizes = qw/B KB MB GB TB/;
my @numbers = (40000000000, 3000000000, 200000000, 7000000, 5000, 234);
my @print = map {convert($_)} @numbers;
sub convert ($) {
my $num = length($_[0]) % 3 == 0 ? int(length($_[0]) / 3) - 1 : int(length($_[0]) / 3);
return sprintf "%.02f %s", $_[0] / (1024**($num)), $sizes[$num];
}
1 KB | 1024 Bytes | (1024**1)
1 MB | 1048576 Bytes | (1024**2)
1 GB | 1073741824 Bytes | (1024**3)
[b]#!/usr/bin/perl[/b]
@units = qw( bytes KB MB GIGs );
@sizes = (40000000000, 3000000000, 200000000, 7000000, 5000, 234);
foreach (@sizes) {
computeSize($_, $x=3);
}
sub computeSize {
$size = shift;
$size /= (1024 ** $x);
if ($size >= 1) {
printf("%.2f", $size);
print " " . $units[$x] . "\n";
} else {
computeSize($_, $x--);
}
}
[b]#!/usr/bin/perl[/b]
@units = qw( bytes KB MB GIGs );
@sizes = (40000000000, 3000000000, 200000000, 7000000, 5000, 234);
foreach (@sizes) {
$x = 3;
do { $size = $_ / (1024 ** $x--) } until $size >= 1;
print int($size*100)/100 . "\t" . $units[$x+1] . "\n";
}