Vidyalelo
MySQL · Q404

MySQL

Programming · MySQL · question 404

Q404

Which datatype is best suited to store currency values?

A.
INT
B.
FLOAT
C.
DOUBLE
D.
DECIMAL
Answer

Answer: Option D

Solution

Answer: Option D
Solution:
This question asks about the best way to store money in a MySQL database. Let's break down the options:
Option A: INT - Integers are whole numbers. They're good for counting things, but not for money because money can have decimals (like $10.50).
Option B: FLOAT - Floats are numbers with decimals. They seem like a good choice for money, but they can have rounding errors. This means small amounts of money might get lost due to how the computer stores the numbers.
Option C: DOUBLE - Doubles are like floats, but they can hold even larger numbers with decimals. They also have rounding errors like floats.
Option D: DECIMAL - This is the best option for storing money! It's designed to handle decimals precisely, so you won't lose any money due to rounding errors.
Therefore, the correct answer is DECIMAL.