lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 3/30/06, Andrew Sidwell <> wrote:
> Hash: SHA1
> Hi,
> 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))
> false
> 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: