Numeric Data Types in MySQL

MySQL provides exact integer and fixed-point types as well as approximate floating-point types. Select the type based on range, exactness and storage requirements.

Quick query: DECIMAL is suited to exact fixed-point values, such as prices.

SELECT CAST(199.95 AS DECIMAL(10,2)) AS price;

Expected result

price
199.95
On this page — Show page sectionsHide page sections

Integer types

TypeBytesSigned rangeUnsigned range
TINYINT1-128 to 1270 to 255
SMALLINT2-32,768 to 32,7670 to 65,535
MEDIUMINT3-8,388,608 to 8,388,6070 to 16,777,215
INT4-2,147,483,648 to 2,147,483,6470 to 4,294,967,295
BIGINT8-2^63 to 2^63-10 to 2^64-1

DECIMAL for exact values

DECIMAL(M,D) stores exact fixed-point values. M is total precision and D is the scale.

price DECIMAL(10,2)

This is a common choice for currency-like values.

FLOAT and DOUBLE

FLOAT and DOUBLE are approximate floating-point types. Use them for scientific measurements where approximation is acceptable, not for values that require exact decimal arithmetic.

Older examples often use integer display widths such as INT(3). A display width does not restrict an integer to three digits and should not be used as a range rule.

Numeric columns in a working table

For example, an inventory item needs an ID, a quantity, a price and possibly an approximate measurement. Create this sample table in a test database:

CREATE TABLE numeric_demo (
    id INT UNSIGNED NOT NULL,
    quantity SMALLINT UNSIGNED NOT NULL,
    unit_price DECIMAL(10,2) NOT NULL,
    weight_kg DOUBLE,
    PRIMARY KEY (id)
);

Insert one row, then calculate the value of the quantity in stock:

INSERT INTO numeric_demo (id, quantity, unit_price, weight_kg)
VALUES (1, 3, 199.95, 1.25);

SELECT quantity, unit_price,
       quantity * unit_price AS total_price
FROM numeric_demo
WHERE id = 1;

Expected output (example data)

quantityunit_pricetotal_price
3199.95599.85

DECIMAL vs FLOAT vs DOUBLE

DECIMAL(10,2) permits 10 total decimal digits, with 2 after the decimal point. FLOAT and DOUBLE use approximate binary floating-point representations and are suitable where small approximation errors are acceptable, such as measurements. Avoid approximate types for money that requires exact decimal arithmetic.

Signed and unsigned integers

UNSIGNED removes negative values from supported integer types and increases the positive range. For a count or ID that cannot be negative, it may be appropriate; choose it based on your data model and compatibility with related columns.

Check a numeric column's definition

SHOW COLUMNS FROM numeric_demo;

For related examples, see BOOLEAN/TINYINT, ROUND() and CREATE TABLE.

Back to top ↑




Subscribe to our YouTube Channel here



plus2net.com




SQL Video Tutorials










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer