Reputation: 557
My database has a float(8,2)
field and has a value with two decimal points (5.49). While fetching it to php, the value gets rounded to one decimal point (5.5) although I expect it to be to two decimal point (5.49) and not rounded off.
I found a solution by changing the datatype to decimal
, but I can not do so for production environment (some reason). How can I restrict the round off?
I am using laravel-4.2 php-5.4 and mysql-5.6 and laravel-eloquent.
Thanks in advance.
Upvotes: 0
Views: 2060
Reputation: 11
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
. MySQL performs rounding when storing values, so if you insert 999.00009
into a FLOAT(7,4)
column, the approximate result is 999.0001
.
Upvotes: 1