jericopulvera's avatar

What is the right data type for e-commerce price?

$table->decimal('price', 5, 2); this is what I am using right now. is there a better data type than this for pricing accuracy?

0 likes
2 replies
SaeedPrez's avatar

I usually save 5.99 as 599 in an integer data type column.

2 likes
ankitparmar372's avatar
Level 6

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

1 like

Please or to participate in this conversation.