MySQL Numeric Types
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
);
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
31 Mar 2026
Views
16
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Perplexity 4
Google 3
Unknown AI 2
ChatGPT 1
Ahrefs 1
Also referenced
How they use it
crawler 11
Related categories
⚡
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