Level 50
I usually save 5.99 as 599 in an integer data type column.
2 likes
$table->decimal('price', 5, 2); this is what I am using right now. is there a better data type than this for pricing accuracy?
Since money needs an exact representation don't use data types that are only approximate like float. You can use a fixed-point numeric data type for that like
numeric(15,2)
15 is the precision (total length of value including decimal places)
2 is the number of digits after decimal point
for more details you can refer this link.
https://dev.mysql.com/doc/refman/5.7/en/fixed-point-types.html
Please or to participate in this conversation.