SPUG: Rounding error

Amit Sett amitsett at gmail.com
Wed Nov 23 10:10:14 PST 2011


Thanks Fred. I did things in pennies and it worked.
-Amit


On Wed, Nov 23, 2011 at 9:48 AM, Fred Morris <m3047 at m3047.net> wrote:

> On Wednesday 23 November 2011 10:24, Amit Sett wrote:
> > [...] The program works well except for some cases where it short
> > changes a customer by 1 penny [...]
>
> Try doing things in pennies, e.g. a dollar is 100 pennies.
>
> Do you know what a repeating decimal is, and do you know what causes them?
> Basically any time you divide 1 by a prime number not in your number base
> you
> get a repeating decimal.
>
> For instance in base 10 (2 * 5) if you divide by 3, 7, 11, 13, etc. you
> get a
> repeating decimal.
>
> In base 2, dividing by 3, 5, 7, 11, etc does the same thing. If you divide
> by
> 100 (2 * 2 * 5 * 5) you get a repeating decimal, or in other words there is
> rounding error.
>
> ObMathNote: 0.9999999... actually is provably equal to 1. ;-)
>
> --
>
> Fred
>
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
>     POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
>    MEETINGS: 3rd Tuesdays
>    WEB PAGE: http://seattleperl.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/spug-list/attachments/20111123/366d02b7/attachment.html>


More information about the spug-list mailing list