When working with monetary values in SQL, always prioritize precision – rounding errors are unacceptable when dealing with money. Here's what we should know:
The Right Choice: DECIMAL or NUMERIC
-- Good: Stores values exactly as entered
DECIMAL(15, 4) -- Can hold up to 15 digits before and 4 after the decimal
The Wrong Choices
Avoid these for currency:
FLOAT/REAL/DOUBLE – These use binary floating-point and will cause rounding errors
Integer types – While you could store cents as integers (e.g., 1000 for $10.00), it makes queries harder to write and understand