[interchange-bugs] [rt.icdevgroup.org #349] Vend::Util::round_to_frac_digits() simplification

Peter peter at pajamian.dhs.org
Tue Mar 20 06:56:38 UTC 2012


On 20/03/12 04:47, Anonymous via RT wrote:
> round_to_frac_digits()  produces ".00" when called with (0, 2).  It
> also parses the integers incorrectly: in normal Perl "1." is a valid
> number, as is "+3", but "-" is not valid.
> 
> Nearly all of the function logic can be replaced with:
> 
> printf "%.*f", $digist, $num;

As was just discussed with Mike on the mailing list, rounding with
sprintf (indeed any rounding that relies on floating point arithmetic)
has issues with floating point errors and should not be relied upon.  I
think it's best to just fix the issues pointed out with the current
function.


Peter



More information about the interchange-bugs mailing list