in reply to Still puzzled by floats

However, 19.95 can't be precisely represented as a binary floating point number,...,

Why not? Surely there is a bit pattern in the IEEE float format that precisely represents 19.95 (1.995E1). If a float is stored in,say, 32 bits on a particulat platfrom, some bits are for the mantissa and some are for the exponent...

That's not how it works.

What you are describing would be a base10 representation -- ie: you store a number and a base 10 exponent. What is typicaly used is a number and a base 2 exponent.

what you want: mantissa * (10 ** exp)
what you get: mantissa * (2 ** exp)

IEEE 854 specifies support for base10 representations, but no one uses it -- what gets used is IEEE 754. When you get a sizable chunk of free time, read through What Every Computer Scientist Should Know About Floating-Point Arithmetic -- in the mean time, John Darcy (Sun's floating point guru) has a great set of slides about Floats in java -- but the information is equally useful for perl programmers.