Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem: Querying Float Fields with a decimal

Status
Not open for further replies.

FireFett

Programmer
Mar 31, 2000
42
US
Hello everyone

I have a table that contains a FLOAT(13,1) field

When I perform a query on it if the select statement on that field tries to find a value of 5.1 it will not return a record.

Example of Data in Table
Rec1 5.0
Rec2 5.1

If I Perform the following SQL Statement

SELECT AcctNum
FROM sl_member
WHERE (AcctNum = 5.1)

No Records Returned but should have returned rec 2

However if I do the following
SELECT AcctNum
FROM sl_member
WHERE (AcctNum = 5)

Or

SELECT AcctNum
FROM sl_member
WHERE (AcctNum = 5.0)

Rec 1 is returned

Anyone have a solution for me being able to select on a float field?
 
Thanks I had just found that out when I got your reply.

I was basing my data types on the Visual basic/MySQL data Types Document that says Singles in VB = Floats in MySQL I have since made changes to the table to convert the floats to doubles.
 
I'm not sure that columns of type DOUBLE are necessarily going to fix your problem.

In your specific example, you were querying for the value 5.1. 0.1 is, in IEEE binary floating-point format, the equivalent of an decimal infinitally-repeating decimal.

I recommend you look at DECIMAL columns or, since you're only using one decimal place, storing all your numbers as integers and shifting the decimal as needed when you display values or accept input from a user to do a search.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top