I've spent a good amount of time trying to figure out why my decimals are being turned into a string I've used casting on my model. I've done some searching but however, I'm not finding a working answer. Some suggested casting to a float but isn't a float bad practice for dealing with actual prices? I should mention I'm using Laravel 5.8 and MariaDB
A decimal field in the database is basically a float, so a float should be good here!
If you want to store money in the database it's better to use plain integers. So for example if you have price of 5.67 you insert 567 in the database. From there you can convert it back to 5.67 if you wish ;)
Using strings and the BCMath library is the only precise way to handle decimal values in PHP (besides using integers).
@bobbybouwmann Decimal and float are not "basically the same", they are very different. You should never store precise data like amounts of money as a float. Rounding errors will mess up your calculations.
That is done by the pdo db driver, to preserve the actual decimal number.You don't want a precise decimal in mysql being converted to a php floating point variable, introducing imprecision. Your calculations wouldn't be accurate. PHP doesn't have a decimal datatype, they get stored as floats.