Vidyalelo
MySQL · Q1051

MySQL

Programming · MySQL · question 1051

Q1051

The datatype best suited to store currency values is . . . . . . . .

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 (currency) in a MySQL database.
Here's why the answer is DECIMAL:
* INT (Integer): Stores whole numbers only. Not good for money because it can't represent cents or fractions.
* FLOAT (Floating Point): Stores numbers with decimals, but it's not precise enough for currency. Small errors can accumulate, leading to incorrect calculations.
* DOUBLE (Double Precision Float): Similar to FLOAT, but with more decimal places. Still not ideal for accurate financial calculations.
* DECIMAL: The best choice for currency! It stores numbers with a fixed number of decimal places, ensuring precise calculations for money.
Therefore, the correct answer is D: DECIMAL**.