Single Data type adds extra digits

  • Thread starter Thread starter Guest
  • Start date Start date
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?
 
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.
 
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 <--
 
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,
 
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.

--
 
Back
Top