Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my float store in MYSQL as .9999 when it's greater than 1?

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?

like image 339
T. Brian Jones Avatar asked Nov 11 '11 09:11

T. Brian Jones


People also ask

What will be the storage pattern for FLOAT in MySQL?

Explanation: Float(4,2) allowed at most 2 digit at right of the decimal and left of the decimal.

How does FLOAT work in MySQL?

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 .


1 Answers

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.

like image 102
Maxim Krizhanovsky Avatar answered Sep 22 '22 17:09

Maxim Krizhanovsky