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.

I was just doing that to see what $y is :) since I can't get the result from bdiv, IE "will give 0.66666" but how do you get 0.66666 from it?


What are you trying to do here? Do you really need Math::BigFloat?

wholenumber / wholenumber = whatever

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)

the two numbers being divided will always be whole numbers, so just for the output.


I have the sprintf idea up to 14 decimals with plain perl, but what if I want

1/3 up to 50 decimal places?

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) ;

Ok, but how do I get 0.333333333333333333333333333333 from 1/3 into a variable :)


print $y->bround(5) and any other function just prints "inf",

--
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