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?
From the MySQL Numeric Types page:
float(4,4) means a 4 digit number, with all 4 digits to the right of the decimal point; 0.9999 is the biggest number it can hold.
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
This isn't directly an answer to your question, but you shouldn't use floats for that. Rounding issues are well known for floats. Use a
decimal
if you want precision.It's because of the values you're passing in. You're allowing 4 digits after the decimal point, but only 4 digits in total so the maximum it can store is .9999. Change it to
float(5,4)
to save it correctly, or increase the 5 if you think you'll need an even greater number.