Decimal types
- SQL course
- Beginner
- Lesson 25/115
- 4 min
Learn DECIMAL, NUMERIC, FLOAT decimal types.
Decimal types
For decimal numbers you use DECIMAL, NUMERIC and FLOAT. DECIMAL is preferred for money; FLOAT gives approximate values.
CREATE TABLE products (
price DECIMAL(10, 2),
rate FLOAT
);Price has 10 digits, 2 decimals; rate is an approximate decimal.
The table products is created.
Decimal types — details
DECIMAL(10, 2) means 10 total digits, 2 after the decimal point. FLOAT is used in scientific computing but not for money because of rounding errors.
Practice Decimal types
Add a price DECIMAL(10,2) column to products.
Starter code
-- price column
CREATE TABLE products (
priceSample solution
CREATE TABLE products (
price DECIMAL(10, 2)
)Expected output
Tablo oluşturuldu
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Decimal type
CREATE TABLE t (price ____(10, 2));
CREATE TABLE t (price DECIMAL(10, 2));
Explanation: DECIMAL is the right answer.
2 Which type is preferred for money?
- DECIMAL Correct answer
- FLOAT
- INT
- TEXT
Explanation: DECIMAL keeps exact values; FLOAT rounds.
3 Decimal types: match the terms
| Term | Meaning |
|---|---|
DECIMAL |
money |
FLOAT |
approximate |
INT |
integer |
CHAR |
text |