MySQL more than microtime timestamp

I have one PHP script inserting rows into a MySQL database. Each line has a "created_at" field, which is populated with the PHP microtime (true) function value and inserted as double. (microtime because I need something more accurate than the second)

I have another PHP script that selects strings based on this created_at field.

When I go ahead and select like this: SELECT * FROM `ms_voltage` WHERE created_at > 1302775523.51878 I get a result set, as the first row, a row with exactly this value for created_at.

This comes from my PHP script and from inside PhpMyAdmin when the request is manually executed. But not always, not for every value. Only once and for all.

How is this possible? I did not ask for more / equal, I want strictly more. Can I ignore something related to type?

+1
source share
3 answers

Yes, floating point arithmetic can do this sometimes. To understand why, it is useful to understand that just as not all numbers can be accurately represented in base 10, not all numbers can be accurately represented in base 2.

For example, β€œ1/3” can be written in base 10 as 0.33333 or 0.33334. None of them are β€œright”; they are just the best we can do. The β€œDUAL” in base 10 can be 0.33333333333 or 0.33333333334, which is double the numbers, but still not β€œright.”

: DECIMAL, INT ( , , 10000 100000, , int).

+4

DOUBLE . DECIMAL.

+4

? microtime true float float, .51878, , , , .

If you really don't need a float, I would convert the result of the row to int or even two columns in seconds and seconds. Then you can use> or <according to known values, without worrying about the inaccuracy of the floating point value.

+2
source

All Articles