Search notes:

Perl module Number::Bytes::Human

use warnings;
use strict;

use Number::Bytes::Human qw(format_bytes);

# use bignum;

  show(                             0);
  show(                             1);
  
  show(                          1000);
  show(                          1024);
  
  show(                     1000*1000);
  show(                     1000*1024);
  show(                     1024*1024);
  
  show(                1000*1000*1000);
  show(                1000*1000*1024);
  show(                1000*1024*1024);
  show(                1024*1024*1024);

# Too large values? bignum doesn't help...
#
# show(           1000*1000*1000*1000);
# show(           1000*1000*1000*1024);
# show(           1000*1000*1024*1024);
# show(           1000*1024*1024*1024);
# show(           1024*1024*1024*1024);

# show(      1000*1000*1000*1000*1000);
# show(      1000*1000*1000*1000*1024);
# show(      1000*1000*1000*1024*1024);
# show(      1000*1000*1024*1024*1024);
# show(      1000*1024*1024*1024*1024);
# show(      1024*1024*1024*1024*1024);
# 
# show( 1000*1000*1000*1000*1000*1000);
# show( 1000*1000*1000*1000*1000*1024);
# show( 1000*1000*1000*1000*1024*1024);
# show( 1000*1000*1000*1024*1024*1024);
# show( 1000*1000*1024*1024*1024*1024);
# show( 1000*1024*1024*1024*1024*1024);
# show( 1024*1024*1024*1024*1024*1024);


sub show { # {{{
    
    my $bytes = shift;

    printf("  %10i   %10s   %10s   %10s\n", 
      $bytes, 
      format_bytes($bytes, {'si' =>  1, base => 1000   }),
      format_bytes($bytes, {'si' =>  1, base => 1024   }),
      format_bytes($bytes, {'si' =>  0, base => 1024000}),
    );

} # }}}

__END__
           0            0            0            0
           1         1.0B         1.0B          1.0
        1000        1.0kB        1000B         1000
        1024        1.1kB       1.0KiB         1024
     1000000        1.0MB       977KiB      1000000
     1024000        1.1MB      1000KiB         1.0M
     1048576        1.1MB       1.0MiB         1.1M
  1000000000        1.0GB       954MiB         977M
  1024000000        1.1GB       977MiB        1000M
  1048576000        1.1GB      1000MiB        1024M
  1073741824        1.1GB       1.0GiB        1049M

Github repository PerlModules, path: /Number/Bytes/Human/script.pl
Perl modules.

Index