Search⌘ K
AI Features

Solution: Use NUMERIC Data Type

Understand how to avoid rounding errors in SQL by using the NUMERIC or DECIMAL data types for fixed-precision decimal values. Explore the concepts of precision and scale and learn how these types store exact numeric values across all rows in a table, helping you manage decimal data accurately.

We'll cover the following...

Instead of FLOAT or its siblings, let’s use the NUMERIC or DECIMAL SQL data types for fixed-precision fractional numbers.

MySQL
ALTER TABLE Bugs ADD COLUMN hours NUMERIC(9,2);
ALTER TABLE Accounts ADD COLUMN hourly_rate NUMERIC(9,2);

Precision and scale

The NUMERIC and DECIMAL data types store numeric ...