How to store average rating in MySQL?

2k Views Asked by At

What MySQL data type suits best for storing average rating values, like movie ratings on IMDB? FLOAT, DECIMAL? Or maybe it will work faster if I round actual values to two decimal places in PHP and save it like INT (8.323243 -> 8.32 -> 832)?

2

There are 2 best solutions below

0
On

The most performant, fast and small data type will indeed be INT. Sorting, searching, etc. will be the best with this data type, vs. decimal and/or float.

0
On

You don't care about precision, so it is not necessary to use decimal. If you want to only use whole numbers, use an int. Else, use a float or double.

Rounding it first in PHP gains you nothing. Converting it in PHP between int and double will be slower than storing doubles in the database.