Skip to content

DECIMAL

CREATE TABLE Products (
ProductID INT,
Price DECIMAL(5, 2)
);
INSERT INTO Products (ProductID, Price)
VALUES (1, 23.45),
(2, 150.99),
(3, 100.00);
SELECT * FROM Products;
+-----------+-------+
| ProductID | Price |
+-----------+-------+
| 1 | 23.45 |
| 2 | 150.99|
| 3 | 100.00|
+-----------+-------+

Here, DECIMAL(5,2) is used to store numbers with 5 digits, 2 of which are decimals. This is used in the ‘Price’ column. The output shows the products with their associated prices. With DECIMAL type, calculations are more precise than with FLOAT or DOUBLE. The example creates a ‘Products’ table, inserts rows into it, and then performs a SELECT query to display the contents.