On Wed, 16 Mar 2005 13:39:34 -0600, JupiterHost.Net
<[EMAIL PROTECTED]> wrote:
> Hello,
> 
> My goal is to divide two whole numbers and get the results to a given
> number of decimals.

[cut]

> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> use Math::BigFloat;
> use Data::Dumper;

[cut]

> my $x = Math::BigFloat->new(2);
> Math::BigFloat->precision(5);           # 5 digits max
> my $y = $x->copy()->bdiv(3);               # will give 0.66666

> print Dumper $y;
> 
> The docs says "will give 0.66666" so how does one get $y to give you that?
> 
> That is what I can't seem to find and the Dump of $y doesn't seem to
> contain any part of the answer...
> 

I'm not sure where in the docs you found the Data::Dumper hint, but
it's probably not what you want.

What are you trying to do here?  Do you really need Math::BigFloat? 
Do you need to specify precision for the calculations, or just for the
output? and are you looking for the result to be truncared (0.66666)
or rounded (0.66667)?  Based on what you've shown us so far, I'd say
your best bet would be:

   my $x = 2;
   my $y = $x/3;
   printf "%.7s\n", $y;   # truncated
   # printf "%.5f\n', $y   # rounded

You can control your precision by storing your variables with sprintf,
too, if you need to.  If you realy need Math::BigFloat, see if
accuracy() and bround() will do what you need, e.g.:

   $y->bround(5) ;

HTH,

--jay

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to