473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

MySQL, MyODBC and ACCESS 2003

Ok I have an interesting problem. I have written a database in Access
to connect to our web shop and update prices etc from a supplier feed.
It works almost perfectly!

The prices are doubles, I am using ADO in access to connect via myodbc
(with options don't optimize column width, Allow big results and
change bigint to int). Everything works ok except if the price is
8351.41 in the code it puts this exact price into the price field of
the table, everything is fine, but when I update the price goes to
8351.41000000001 (not sure on the exact number of 0 but it is a lot!).

I have tried converting the value to a string then to a double before
writing it to the database, to make sure there are no hidden decimals
but it's the same.

I have tried myodbc 3.51.09 and 3.51.11 and it's the same on both!
In fact if I link the table in access and manually type in 8351.41
then move to a different row it changes it to 8351.41000000001!!

Am I going nuts or is this some kind of annoying bug?
Jul 23 '05 #1
6 2053
How did you define that column type? Did you use float? You can alter
the table to change the precision.

mysql> create temporary table test (price float);
Query OK, 0 rows affected (0.04 sec)

mysql> desc test;
+-------+-------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------+------+-----+---------+-------+
| price | float | YES | | NULL | |
+-------+-------+------+-----+---------+-------+
1 row in set (0.00 sec)

mysql> alter table test change price price float(10,2);
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc test;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| price | float(10,2) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
1 row in set (0.00 sec)

mysql> insert into test (price) values (8.3566677777);
Query OK, 1 row affected (0.00 sec)

mysql> select * from test;
+-------+
| price |
+-------+
| 8.36 |
+-------+
1 row in set (0.00 sec)

Jul 23 '05 #2
Dave wrote:
In fact if I link the table in access and manually type in 8351.41
then move to a different row it changes it to 8351.41000000001!!

Am I going nuts or is this some kind of annoying bug?


For what it's worth, this is an inescapable characteristic of
representing floating-point numbers on computers. The inexactness of
IEEE floating point numbers comes from the difference between base-2 and
base-10. In a similar way that 2/3 is a non-repeating number in
base-10, some fractions are non-repeating when represented in binary.

Then because the computer has finite space to store them, you get
inexactness problems like you see above. Similarly, 2/3 could be stored
as 0.6666667 in base-10, but that's not exactly the same value as 2/3.

Software that needs to store floating-point values with more exactness
need to store them differently. Basically it needs to store 8351.41 as
the integer 835141, plus the value 2 as the "scale," or the number of
digits to the right of the decimal. MySQL seems to do this for you,
when you declare a scale value for the FLOAT datatype, as Bill Turczyn
described in his message.

Regards,
Bill K.
Jul 23 '05 #3
the price field is a double with 0,0. the wierd thing is if i set it
to a 2 decimal place i do not get the symptom mentioned above, but i
get the same problem, access will not update the record again untill i
delete the information in the price field, but if i use some mysql
admin software to change the field i can change it no problem. The
error access gives is someone else has altered the record since it was
written, which is obviously not the case as the timestamp has not
changed.

Any thoughts?
Jul 23 '05 #4
Also, all the information i see on the mysql site is to only use
doubles, not floats if you are using in conjunction with access (that
is why i have it as double) originally it was float, by the way, i
have the same problem when it is set to float, but for ALL records!
Jul 23 '05 #5
"Dave" <tr******@centatek.com> wrote in message
news:c8**************************@posting.google.c om...
Ok I have an interesting problem. I have written a database in Access
to connect to our web shop and update prices etc from a supplier feed.
It works almost perfectly!

The prices are doubles, I am using ADO in access to connect via myodbc
(with options don't optimize column width, Allow big results and
change bigint to int). Everything works ok except if the price is
8351.41 in the code it puts this exact price into the price field of
the table, everything is fine, but when I update the price goes to
8351.41000000001 (not sure on the exact number of 0 but it is a lot!).

I have tried converting the value to a string then to a double before
writing it to the database, to make sure there are no hidden decimals
but it's the same.

I have tried myodbc 3.51.09 and 3.51.11 and it's the same on both!
In fact if I link the table in access and manually type in 8351.41
then move to a different row it changes it to 8351.41000000001!!

Am I going nuts or is this some kind of annoying bug?


It *drive* you nuts, but it's not a bug. More like a design limitation of
modern computers. The ODBC driver and ADO are not to blame.

Contrary to popular opinion, the float type is not the most appropriate type
for dealing with dollars and cents. By their very nature, floats are only
approximations gauranteed to leave penny balancing accountants dissatisfied.
Bill Karwin explained the reasons quite well.

The best fix would be to use the DECIMAL type instead of FLOAT.

A *second* best solution, if you are *stuck* with FLOAT, is to use of the
ROUND function both when SELECTing and INSERTing dollar values. If you
specify 4 decimal places, the floating point precision of MySQL will
probably suffice to keep your pennies in line and irrelevant decimal places
suppressed. But there are no gaurantees you won't lose a penny here and
there if you do lots of arithmentic.

DECIMAL type is how you should store $ and cents.
Thomas Bartkus
Jul 23 '05 #6
Hi Guys, thanks for the info. I have made the change to decimal 10,2
and it seems to have worked. Just have to run through the update once
more to double check that access can still update the record.

The table is part of a web shop that we have purchased, the default
for the price fields was float, and I just presumed that they needed
to be a float for the shop to work but apparently not.

Once again thanks for the help.
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ryan Schefke | last post by:
------=_NextPart_000_0077_01C34C8B.2B90C960 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit ..I just sent this out to the win32 distribution list but no one has...
3
by: Steve Farber | last post by:
I'm not especially new to databases and I have used ODBC before with other data sources, but I cannot seem to get Access 2003 to talk to MySQL 4.0.15. I have MySQL running with new tables...
11
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time...
2
by: Beda Christoph Hammerschmidt | last post by:
MySQL, Access, ODBC, Replication Hello, i have a central mysql database that is accesed by multiple clients running MS Access with ODBC. This works fine if Access has a permanent connection...
2
by: pholck | last post by:
A newbie question here: I'm linking to a MySQL backend table with a million+ records, where two fields are of type datetime. However Access considers those fields to be text. Can't seem to get...
1
by: gordon.dtr | last post by:
Hi, Has anyone had this problem ? I am using MySQL ODBC 3.51 Driver, with MS Access 2003 and MySQL 4.1.11 standard log. I created my tables in MS Access, then exported them via ODBC to an...
2
by: David | last post by:
Hi, Has anyone had this problem ? I am using MySQL ODBC 3.51 Driver, with MS Access 2003 and MySQL 4.1.11 standard log. I created my tables in MS Access, then exported them via ODBC to an...
5
by: csgraham74 | last post by:
Hi, I have recently decided to start using MYSQL instead of MS Access 2003. After reading through numerous articles i have learnt that i can use access as a GUI for making changes etc to the...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.