Maybe this is a more general MySQL or PHP question deriving from my lack of knowledge in those fields, but...
So I have an app on Laravel 5.4, Database is MySQL 5.7.17
I have a column in talbe, created via migration:
$table->float('operator_price', 9, 2)->nullable()->change();
(this, according to Laravel docs, should mean that column has type 'FLOAT' with 9 total digits and 2 after decimal point)
When user enters 1000.25 in the form field and saves - it's saved as '1000.25',
But if user enters 10000.25 - it's saved as '10000.2'.
So it cuts the last digit if the number is over 9999.
What may be the reason and how can I fix it?
Thank you.
UPDATE: I've done SHOW COLUMNS FROM tours;
and it shows that column 'operator_price' has type 'float':
Actually float/double is not as precise as decimal. For monetary data, the decimal type is recommended, so you should probably use:
$table->decimal('operator_price', 10, 2); // instead of float
Read this for some detailed information and float manual from MySql.
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