0
0
MySQLquery~5 mins

Decimal and floating-point types in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main difference between DECIMAL and FLOAT types in MySQL?
DECIMAL stores exact numeric values with fixed precision and scale, ideal for financial data. FLOAT stores approximate values using floating-point representation, which can introduce rounding errors.
Click to reveal answer
beginner
How do you define a DECIMAL column with 10 digits total and 2 digits after the decimal point?
Use DECIMAL(10,2). This means 10 digits total, with 2 digits to the right of the decimal point.
Click to reveal answer
intermediate
Why might FLOAT or DOUBLE types cause rounding errors in calculations?
FLOAT and DOUBLE use binary floating-point representation, which cannot exactly represent some decimal fractions, causing small rounding errors in calculations.
Click to reveal answer
beginner
Which data type should you use for storing currency values in MySQL and why?
Use DECIMAL because it stores exact values without rounding errors, which is important for accurate financial calculations.
Click to reveal answer
intermediate
What happens if you insert a value with more decimal places than defined in a DECIMAL column?
MySQL rounds the value to fit the defined scale (number of decimal places). For example, inserting 12.345 into DECIMAL(5,2) stores 12.35.
Click to reveal answer
Which MySQL data type stores exact numeric values with fixed precision?
AVARCHAR
BFLOAT
CDECIMAL
DDOUBLE
What does DECIMAL(8,3) mean in MySQL?
A8 digits total, 3 digits after decimal point
B3 digits total, 8 digits after decimal point
C8 digits after decimal point
D3 digits total
Which data type is more likely to cause rounding errors?
ADATE
BDECIMAL
CCHAR
DFLOAT
If you need to store money values accurately, which type should you choose?
ADECIMAL
BDOUBLE
CFLOAT
DTEXT
What happens if you insert 123.4567 into DECIMAL(6,2)?
AStored as 123.45
BStored as 123.46
CError: too many decimal places
DStored as 123.4567
Explain the difference between DECIMAL and FLOAT types in MySQL and when to use each.
Think about precision and rounding.
You got /4 concepts.
    Describe how MySQL handles values with more decimal places than defined in a DECIMAL column.
    Consider what happens to extra digits.
    You got /3 concepts.