UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Numeric Field Stores Wrong Value, Access 2007    
 
   
TomS
post Dec 16 2019, 12:17 PM
Post#1



Posts: 75
Joined: 29-January 03



Hello,
I have a table with a field that is numeric data type and field size set to single. When I enter a value of 3.7 it stores it as 3.70000004768372. Does anyone know why?
Go to the top of the page
 
theDBguy
post Dec 16 2019, 12:34 PM
Post#2


UA Moderator
Posts: 77,727
Joined: 19-June 07
From: SunnySandyEggo


Hi TomS. How exactly did you "enter" the value? I just tried it on a test table, and it stored 3.7 after I typed it into the field.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
GroverParkGeorge
post Dec 16 2019, 01:00 PM
Post#3


UA Admin
Posts: 36,987
Joined: 20-June 02
From: Newcastle, WA


You are probably experiencing one of the "problems" with certain floating point numbers

As theDBGuy suggests "how" you came up with this value is important because it looks like "entering" it means you are actually copying it from somewhere else, or calculating it somehow and storing that.

Depending on the requirement, the Currency datatype is sometimes suggested as a better alternative to single or double.

--------------------
My Real Name Is George. Grover Park Consulting is where I did business for 20 years.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 
TomS
post Dec 16 2019, 02:33 PM
Post#4



Posts: 75
Joined: 29-January 03



I entered it as 3.7

I did not copy and paste it. If I you write a query and multiply the field by 10000000000, it will return: 37000000476.8372. Seems like it should return: 37000000000
Go to the top of the page
 
theDBguy
post Dec 16 2019, 02:54 PM
Post#5


UA Moderator
Posts: 77,727
Joined: 19-June 07
From: SunnySandyEggo


Okay, I see what you mean. So, as George was saying, this could be a matter of precision. If you look at this article on the Single data type, you'll see this precaution about precision:

QUOTE
Programming Tips

Precision. When you work with floating-point numbers, keep in mind that they do not always have a precise representation in memory. This could lead to unexpected results from certain operations, such as value comparison and the Mod operator. For more information, see Troubleshooting Data Types.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
projecttoday
post Dec 16 2019, 02:58 PM
Post#6


UtterAccess VIP
Posts: 11,809
Joined: 10-February 04
From: South Charleston, WV


I recommend using the decimal format. There is no conversion differential. And it works just fine.

--------------------
Robert Crouser
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    5th April 2020 - 01:10 AM