Single Data type adds extra digits

G

Guest

I have a question about the Single Data type. When I create a table and have
a numeric field of Single Data Type and enter some values (in this example, I
entered 1.1, 2.2, 3.3, 4.4, 5.5, 6.6) and close - then go create a TOTALS
query with a SUM of this field, I would expect to get a result of 23.1 - BUT
instead, the result shows 23.1000000238419. Furthermore, If I go into table
design and change the data type to DOUBLE, the fields change to:
(1.10000002384186, 2.20000004768372, 3.29999995231628, 4.40000009536743, 5.5,
6.59999990463257). Any ideas what is happening here? Where do the extra
digits come from?
 
D

Douglas J. Steele

It's an artifact of how computers store numbers. Just as there are certain
numbers that humans can't represent exactly in base ten (think of 1/3 or
1/6), so too are they numbers that computers can't represent exactly in
binary.

Do a search on "numeric precision" or "floating point numbers" for more
information.
 
S

Stefan Hoffmann

hi Luke,

Luke said:
I have a question about the Single Data type. When I create a table and have
a numeric field of Single Data Type and enter some values (in this example, I
entered 1.1, 2.2, 3.3, 4.4, 5.5, 6.6) and close - then go create a TOTALS
query with a SUM of this field, I would expect to get a result of 23.1 - BUT
instead, the result shows 23.1000000238419. Furthermore, If I go into table
design and change the data type to DOUBLE, the fields change to:
(1.10000002384186, 2.20000004768372, 3.29999995231628, 4.40000009536743, 5.5,
6.59999990463257). Any ideas what is happening here? Where do the extra
digits come from?
SINGLE and DOUBLE are not a precise data type.

http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems


mfG
--> stefan <--
 
G

George Nicholson

In addition to the other responses:

Unless you need more than 4 decimal precision, use a Currency data type
rather than Single or Double.

HTH,
 
J

Jamie Collins

In addition to the other responses:

Unless you need more than 4 decimal precision, use a Currency data type
rather than Single or Double.

I think you meant decimal *scale*.

If they require a decimal scale of anything other than four, or if
banker's rounding is not approproate, I would suggest they use the
DECIMAL data type, being the Access/Jet engine's native type for
decimal numerics e.g.

SELECT TYPENAME(0.5)

returns 'Decimal'.

Jamie.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top