Friends,

I have never used Math::BigInt before. So I came up with an excuse to write a script that would use it. I wanted to write a simple script that would tell me how many CDs would be needed to hold X Gigabytes of data. Here's the script ...

#!/usr/bin/perl -w use strict; use Math::BigInt; #BigInt KiloByte Unit my $KB = Math::BigInt ( "1024" ); #BigInt MegaByte Unit my $MB = Math::BigInt ( $KB->bmul( $KB ) ); #BigInt GigaByte Unit my $GB = Math::BigInt ( $MB->bmul( $KB ) ); my $arg1 = Math::BigInt->new( shift ); # arg1 is in GBs my $GBarg1 = Math::BigInt->new( $arg1->bmul( $GB ) ); my $arg2 = Math::BigInt->new( shift ); # arg2 is in MBs my $MBarg2 = Math::BigInt->new( $arg2->bmul( $MB ) ); # why rc is 0? my $rc = $GBarg1->bdiv( $MBarg2 ); print "rc is [$rc]\n";
When I run this I get the output of:
$ ./whomany.pl 2 675 rc is [0]
What am I doing wrong here?

Thanks

update: Fixed typo (missing my $arg2) pointed out by Paladin.


In reply to Math::BigInt Newbee question. by Plankton

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.