[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Floating point
- From: "Ben Sunshine-Hill" <sneftel@...>
- Date: Thu, 30 Mar 2006 01:13:29 -0800
On 3/30/06, Andrew Sidwell <email@example.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> I'm wondering if anyone knows of a way to make sure a value is only to
> two decimal points? I only ask because the obvious solution using
> (math.ceil(n * 100) == (n * 100)) doesn't work:
> > print(math.floor(3466) == math.floor(34.66 * 100))
> It would also be quite nice to know why this doesn't work.
It's because most fractional numbers, including most of those with two
decimal places, cannot be exactly represented in floating point form.
For more information, read "What Every Computer Scientist Should Know
About Floating-Point Arithmetic", located here: