473,382 Members | 1,421 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,382 software developers and data experts.

problem querying a float column

I have a column in a MySQL database called price and of type FLOAT(8,2).

I then insert two rows into my table, one where price = 100.00 and one
where price = 100.01, and then try to find these rows:

query 1:
SELECT price
FROM table
WHERE price = 100.00

query 2:
SELECT price
FROM table
WHERE price = 100.01

query 1 successfully returns the row in question, while query 2 returns
the empty set. Using quotes around the search term does not affect it
at all (as it shouldn't since I "should" be searching a float...)

If I try to insert and then search for any number that does not end in
00, I get the empty set. I tried using LIKE and was able to find the
row, but there must be another way to test actual equality.

Thanks very much in advance.
Jul 17 '05 #1
3 1753
Marcus wrote:
I have a column in a MySQL database called price and of type FLOAT(8,2).


It's not a good idea to use FLOAT for numbers which are meant to be
exact. A better data type for prices would be DECIMAL.

JP

--
Sorry, <de*****@cauce.org> is a spam trap.
Real e-mail address unavailable. 5000+ spams per month.
Jul 17 '05 #2
NC
Marcus wrote:

I have a column in a MySQL database called price and
of type FLOAT(8,2).
Bad idea. Money variables should be long integers and
stated in cents (pence, centime, etc.)
there must be another way to test actual equality.


With floats, equality is a difficult concept. Computers
do not compute floating-point numbers with absolute
precision. What you think is 100.00 may in fact be
100.00000000000000002 or 100.00000000000000004, which,
needless to say, will be treated as different numbers.

Cheers,
NC

Jul 17 '05 #3
Marcus wrote:
I have a column in a MySQL database called price and of type

FLOAT(8,2).
<snip>

http://dev.mysql.com/doc/mysql/en/pr...ith-float.html

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #4

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

Similar topics

6
by: B McDonald | last post by:
Hi. I am trying to straighten out some DIV issues in the rendering of my no-tables CSS website. Right now the biggest issue is trying to render 2 columns several DIVs deep in the box model for my...
5
by: javaguy | last post by:
I have a data entry web application that is formatted heavily with tables. Having learned a bit of CSS, I'm hoping to rewrite this using <div> tags. But I have run into a formatting problem that...
2
by: ~john | last post by:
I'm trying to get my header to have 2 images, one for the top left and one for the top right. Here's a link to my page... http://levelwave.com/dev/div/index.html and will eventually be...
2
by: Chris | last post by:
I am trying to create a view that creates a mailing list from two different tables. The t-sql code executes successfully but when I try to open the view I get this error message Error converting...
14
by: varois83 | last post by:
Hi The code I am pasting below is just practice so the colors are goofy, it's to help me see what is where. The text isn't styled either at this time. I am working on a fixed 2...
0
by: whairs01 | last post by:
Could someone help me and telling me how to get my 3 column web page to resize correctly in IE7. When trying to reside my my web page I can only get it to resize to a point before the 2 and 3...
3
by: MM | last post by:
Hi to all, I'm trying to import a tab separated values file onto Excel with the following script: import csv from pyExcelerator import * w = Workbook() worksheet = w.add_sheet('sim1')
3
by: Steve | last post by:
Hi All I have an asp.net 2.0 website with the following css file It uses Master pages and in Firefox 3.04 for windows only, 3 of the web pages don't display the Master page properly The...
1
by: thesti | last post by:
hello, i'm trying to design a web. in the header, i create an outer-div which consist of three inner-divs. the html looks like this <div align="center" id="banner-header"> ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.