I'm storing process time in a MySQL database as a float(4,4).
$start_time = microtime( TRUE );
// things happen in my script
$end_time = microtime( TRUE );
$process_time = $end_time - $start_time;
// insert $process time into mysql table
$process_time always displays correctly when outputted to the command line, but if it's value is greater than 1, it stores into mysql as .9999.
What gives?
Explanation: Float(4,2) allowed at most 2 digit at right of the decimal and left of the decimal.
MySQL permits a nonstandard syntax: FLOAT( M , D ) or REAL( M , D ) or DOUBLE PRECISION( M , D ) . Here, ( M , D ) means than values can be stored with up to M digits in total, of which D digits may be after the decimal point. For example, a column defined as FLOAT(7,4) is displayed as -999.9999 .
float(4,4) means total 4 digits, 4 of them are after the decimal point. So you have to change to 10,4 for example
MySQL permits a nonstandard syntax: FLOAT(M,D) or REAL(M,D) or DOUBLE PRECISION(M,D). Here, “(M,D)” means than values can be stored with up to M digits in total, of which D digits may be after the decimal point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With