Our Laravel application's database runs on a MySQL 5.7.21 server. We store some float values with up to 6 decimal places into a double field with 2 decimal places. MySQL automatically rounds the value to 2 decimals.
Now the rounding function rounds for example 6.025 to 6.02 instead of 6.03. But 5 should be rounded up (mathematically round). MySQL rounds 6.026 correctly to 6.03.
Anyone knows where or how I can fix this?
Otherwise we will round the value before storing it to the DB.
I would definitely go for your second option: round it yourself and than store it. This way you are in charge and not a setting in your database that could be easily overlooked the next time you setup a database.
But no further details if this behavior is editable.
About the 'DECIMAL' data type it say:
When such a column is assigned a value with more digits following the decimal point than are permitted by the specified scale, the value is converted to that scale. (The precise behavior is operating system-specific, but generally the effect is truncation to the permissible number of digits.)
https://dev.mysql.com/doc/refman/5.7/en/fixed-point-types.html
So based on this two lines I would go for making sure in your application that you pass the correct value to your database before storing.