1

I have a field in a table "url_key_weight" with float data type. In one record i have value 2.95 in the float field. When I retrieve and print it from PHP code, it prints 2.9500000476837. But when I run the following querys from PHP

"SELECT * FROM url_key_weight WHERE bid = 2.95"

OR

"SELECT * FROM url_key_weight WHERE bid = 2.9500000476837"

I get nothing.

2 Answers2

1

To have a direct compare you'd have to round

SELECT * FROM url_key_weight WHERE ROUND(bid, 2) = 2.95

Read more about it here.

fancyPants
  • 50,732
  • 33
  • 89
  • 96
0
it is not generally a good idea to compare floating point numbers with = equals operator.

try out this

"SELECT * FROM url_key_weight WHERE bid >= 2.95"
Vijay
  • 8,131
  • 11
  • 43
  • 69