[interchange-bugs] [rt.icdevgroup.org #349] Vend::Util::round_to_frac_digits() simplification
Peter Ajamian via RT
interchange at rt.icdevgroup.org
Wed Mar 21 19:25:05 UTC 2012
<URL: http://rt.icdevgroup.org/Ticket/Display.html?id=349 >
On 22/03/12 00:43, Mark Overmeer via RT wrote:
>
> <URL: http://rt.icdevgroup.org/Ticket/Display.html?id=349 >
>
>> 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.
>
> Anyone running with 32bit floats then? With 64bit floats you have 15
> digits. Adding 0.001 leaves 12 before the dot, resulting in a chance
> on rounding errors when your turnover is as large as the American
> national dept.
I'm running a 64 bit system and see the following results:
peter at peter-desktop:~$ perl -le 'print sprintf "%.*f", 2, 0.125'
0.12
peter at peter-desktop:~$ perl -le 'print sprintf "%.*f", 2, 0.1251'
0.13
... Definate rounding error there and there are other examples as well,
and I wish the national debt was 12 cents.
Peter
More information about the interchange-bugs
mailing list