Difference between numeric, float and decimal in SQL Server

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Difference between numeric, float and decimal in SQL Server

Message par ForumBot »

Difference between numeric, float and decimal in SQL Server
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Difference between numeric, float and decimal in SQL Server

Message par ForumBot »

use the *float* or *real* data types **only if** the precision provided by *decimal* (up to 38 digits) is insufficient

-
Approximate numeric data types(see table 3.3) do not store the exact values specified **for many** numbers; they store **an extremely close** approximation of the value. ([Technet](https://technet.microsoft.com/en-us/library/ms187912(v=sql.105).aspx))

-
Avoid using float or real columns in WHERE clause search conditions, especially the = and operators. It is best to limit float and real columns to > or < comparisons. ([Technet](https://technet.microsoft.com/en-us/library/ms187912(v=sql.105).aspx))

so generally choosing Decimal as your data type is the best bet if

- your number can fit in it. *Decimal precision* is 10E38[~ 38 digits]

- smaller storage space (and maybe calculation speed) of Float is not important for you

- exact numeric behavior is required, such as in financial applications, in operations involving rounding, or in equality checks. ([Technet](https://technet.microsoft.com/en-us/library/ms187912(v=sql.105).aspx))

- **Exact** Numeric Data Types [decimal and numeric - MSDN](https://learn.microsoft.com/sql/t-sql/data-types/decimal-and-numeric-transact-sql)

- numeric = decimal (5 to 17 bytes)

- will map to Decimal in .NET

- both have (18, 0) as default (precision,scale) parameters in SQL server

- scale = maximum number of decimal digits that can be stored to the right of the decimal point.

- money(8 byte) and smallmoney(4 byte) are also Exact Data Type and will map to Decimal in .NET and have 4 decimal points ([MSDN](https://learn.microsoft.com/sql/t-sql/data-types/money-and-smallmoney-transact-sql))

- **Approximate** Numeric Data Types [float and real - MSDN](https://learn.microsoft.com/sql/t-sql/data-types/float-and-real-transact-sql)

- real (4 byte)

- will map to Single in .NET

- The ISO synonym for real is float(24)

- float (8 byte)

- will map to Double in .NET

- All **exact** numeric types always produce the

*(Réponse tronquée)*
Répondre

Revenir à « SQL Server »