Introduction
Decimal and floating-point types store numbers with fractions. They help keep numbers accurate when you need decimals, like money or measurements.
DECIMAL(M, D) FLOAT DOUBLE
price DECIMAL(10, 2)
weight FLOATdistance DOUBLE
CREATE TABLE products ( id INT PRIMARY KEY, name VARCHAR(50), price DECIMAL(8, 2), weight FLOAT ); INSERT INTO products VALUES (1, 'Apple', 0.99, 0.15); INSERT INTO products VALUES (2, 'Banana', 1.25, 0.20); SELECT name, price, weight FROM products;
prices with a column cost FLOAT(7,2), what will be the result of inserting 12345.6789 and then selecting cost?FLOAT(5,2) but notice values like 1234.567 are stored as 1234.56. What is the likely cause and how to fix it?Pass the test and this pattern moves unknown