in reply to Re: Perl 5.8.x floating point representation error
in thread Perl 5.8.x floating point representation error

thank you Dave,

But using Math::BigFloat either did not solve my issue. BigFloat truncates after 16 digits in the exponential part and then adds zeros. Any workaround for this ?

use Math::BigFloat;

Math::BigFloat->accuracy(32);
Math::BigFloat->precision(-32);
$test = Math::BigFloat->new(0.99999999976716932);

print $test;

output:
0.99999999976716900000000000000000

but i need 0.99999999976716932
  • Comment on Re^2: Perl 5.8.x floating point representation error

Replies are listed 'Best First'.
Re^3: Perl 5.8.x floating point representation error
by BrowserUk (Patriarch) on Jan 21, 2009 at 12:40 UTC

    Try it this way (notice the quotes):

    use Math::BigFloat; Math::BigFloat->accuracy(32); Math::BigFloat->precision(-32); $test = Math::BigFloat->new('0.99999999976716932'); print $test; 0.99999999976716932000000000000000

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: Perl 5.8.x floating point representation error
by Anonymous Monk on Jan 21, 2009 at 12:49 UTC
    my $string = "0.99999999976716932"; my $number = 0.99999999976716932; print " string = $string number = $number "; __END__ string = 0.99999999976716932 number = 0.999999999767169