in reply to Re^2: Math::FixedPrecision and bignum clash

in thread Math::FixedPrecision and bignum clash

Hi mje,

IMHO your assumption of rounding in `Math::FixedPrecision` is not true. When you have a look at the constructor of `Math::FixedPrecision` you'll see the the value 3.145 having 3 digits after the point will be rounded to two digits (what is given as second parameter) with ffround (line 80 of sources).

The effect you see is caused by mathematical (odd) rounding (default of Math::BigFloat) with your example. Have a look at these two examples:

#!/usr/bin/perl use strict; use warnings; use 5.010; use Math::FixedPrecision; my $b = Math::FixedPrecision->new(3.145, 2); say $b; # output: 3.14 my $c = Math::FixedPrecision->new(3.155, 2); say $c; # output 3.16

UPDATE: Added output for the reader.

Regards

McA

In Section
Seekers of Perl Wisdom