My Number comes back different

Quote:

>I am storing a percentage value in an Access database as a single. The

>percentage is a variation percentage (ie -20% saves as 0.8 +20% saves as

>1.2) The number is saved as (100 + [Entered %]) / 100 then when I read

>the number from the database I use ([% from database] * 100) - 100. The

>problem is when I use the above example of 20% it returns 20.000001.

>The other numbers I have tested work OK.

>Any one care to have a stab at what is causing this.

>Cheers

>Blair

>--

>Another Message from the Desk of

>===============================================================

>Business Fax +61 3 5722 2587

>Software........Design...Develop...Integrate

Blair,

Single precision numbers are stored in 4 byte fields as

X*10^Y, where X is between -1 and 1, and Y is between about

-38 and about 38. The Y part takes up 2 bytes, so you only

have 2 bytes to represent the X part as a fraction and

rounding inevitably takes place.

If you are working with Integer values then comparisons can be

exact, but with floating-point numbers, like Single and

Double, you have to allow for these small errors as they are

unavoidable. Changing from Single to Double will just reduce

the size of these errors.

Holland Numerics Ltd

Royston, Herts, UK

mobile: +44-(0)850-295556