3

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)?

mskfisher
  • 3,291
  • 4
  • 35
  • 48
Kadilov
  • 145
  • 1
  • 6

2 Answers2

3

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.

Sjoerd
  • 74,049
  • 16
  • 131
  • 175
0

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.

adrien
  • 4,399
  • 26
  • 26