← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

MySQL Numeric Types

database Beginner

Also Known As

MySQL INT BIGINT DECIMAL MySQL money type FLOAT vs DECIMAL MySQL MySQL numeric column

TL;DR

INT, BIGINT, DECIMAL, FLOAT, DOUBLE — the right type prevents overflow, precision loss, and money calculation bugs.

Explanation

Integer types: TINYINT (1B), SMALLINT (2B), MEDIUMINT (3B), INT (4B, ~2.1B signed), BIGINT (8B). UNSIGNED doubles the positive range. DECIMAL(p,s) stores exact decimal values using string-based arithmetic — use for money and prices. FLOAT (4B) and DOUBLE (8B) are IEEE 754 approximate values — never use for currency as 0.1 + 0.2 ≠ 0.3. Use DECIMAL(10,2) for prices, BIGINT for large counters, INT UNSIGNED for most IDs.

Common Misconception

FLOAT is fine for prices since the errors are tiny. In financial calculations, tiny floating-point errors accumulate — £0.001 per transaction × millions of rows causes real discrepancies.

Why It Matters

Using FLOAT for prices introduces rounding errors — £9.99 may be stored as 9.989999999. Overflowing an INT column silently wraps or errors — a high-volume table with INT id will eventually hit 2.1B rows.

Common Mistakes

  • Using FLOAT or DOUBLE for prices, totals, or tax calculations.
  • Using signed INT when UNSIGNED would double the available range for no cost.
  • Not switching to BIGINT before an INT column approaches its limit — the ALTER TABLE is expensive on large tables.

Avoid When

  • Never use FLOAT or DOUBLE for financial values — use DECIMAL.
  • Avoid signed integer types for IDs — UNSIGNED doubles the range at zero cost.

When To Use

  • Use DECIMAL for any monetary or precise decimal value.
  • Use BIGINT UNSIGNED for primary keys on tables expected to exceed hundreds of millions of rows.

Code Examples

✗ Vulnerable
-- FLOAT for money: rounding errors accumulate
price FLOAT NOT NULL,
-- INT for high-volume event log: overflows at ~2.1B rows
id INT AUTO_INCREMENT PRIMARY KEY
✓ Fixed
CREATE TABLE products (
    id        INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, -- up to 4.2B
    price     DECIMAL(10,2) NOT NULL,                  -- exact: 99999999.99
    quantity  MEDIUMINT UNSIGNED NOT NULL DEFAULT 0,   -- up to 16.7M
    weight_kg DECIMAL(8,3)                             -- exact decimal
);

CREATE TABLE events (
    id         BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY -- up to 18.4 quintillion
);

Added 31 Mar 2026
Views 16
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
2 pings W 0 pings T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Perplexity 4 Google 3 Unknown AI 2 ChatGPT 1 Ahrefs 1
crawler 11
DEV INTEL Tools & Severity
⚙ Fix effort: Low
⚡ Quick Fix
Use DECIMAL(10,2) for money, INT UNSIGNED for most IDs, BIGINT UNSIGNED for high-volume tables
📦 Applies To
web cli
🔗 Prerequisites
🔍 Detection Hints
FLOAT or DOUBLE column for price/amount/total/cost
Auto-detectable: ✓ Yes semgrep
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Low Context: Line

✓ schema.org compliant