Skip to content

Commit 68f74ef

Browse files
committed
update float/real with explanation about precision
1 parent 6121580 commit 68f74ef

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

docs/t-sql/data-types/float-and-real-transact-sql.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ Approximate-number data types for use with floating point numeric data. Floating
3030

3131
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
3232

33-
## Syntax
33+
## Syntax
34+
3435
**float** [ **(**_n_**)** ]
3536
Where *n* is the number of bits that are used to store the mantissa of the **float** number in scientific notation and, therefore, dictates the precision and storage size. If *n* is specified, it must be a value between **1** and **53**. The default value of *n* is **53**.
3637

@@ -52,21 +53,28 @@ The [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] **float**[**(n)**]
5253
|---|---|---|
5354
|**float**|- 1.79E+308 to -2.23E-308, 0 and 2.23E-308 to 1.79E+308|Depends on the value of *n*|
5455
|**real**|- 3.40E + 38 to -1.18E - 38, 0 and 1.18E - 38 to 3.40E + 38|4 Bytes|
56+
57+
The float and real data types are known as approximate data types. The behavior of float and real follows the [IEEE 754](https://ieeexplore.ieee.org/document/4610935) specification on approximate numeric data types.
58+
59+
Approximate numeric data types don't store the exact values specified for many numbers; they store a close approximation of the value. For some applications, the tiny difference between the specified value and the stored approximation isn't relevant. For others though, the difference is important. Because of the approximate nature of the float and real data types, don't use these data types when exact numeric behavior is required. Examples of precise numeric values applications include financial or business data, in operations involving rounding, or in equality checks. In those cases, use the integer, decimal, numeric, money, or smallmoney data types.
60+
61+
Avoid using float or real columns in WHERE clause search conditions, especially the = and <> operators. It's best to limit float and real columns to > or < comparisons.
62+
63+
## Converting float and real data
64+
65+
Values of **float** are truncated when they're converted to any integer type.
5566

56-
## Converting float and real data
57-
Values of **float** are truncated when they are converted to any integer type.
58-
59-
When you want to convert from **float** or **real** to character data, using the STR string function is usually more useful than CAST( ). This is because STR enables more control over formatting. For more information, see [STR &#40;Transact-SQL&#41;](../../t-sql/functions/str-transact-sql.md) and [Functions &#40;Transact-SQL&#41;](../../t-sql/functions/functions.md).
67+
When you want to convert from **float** or **real** to character data, using the STR string function is typically more useful than CAST( ). The reason is that STR() enables more control over formatting. For more information, see [STR &#40;Transact-SQL&#41;](../../t-sql/functions/str-transact-sql.md) and [Functions &#40;Transact-SQL&#41;](../../t-sql/functions/functions.md).
6068

6169
Prior to [!INCLUDE[ssSQL16](../../includes/sssql16-md.md)], conversion of **float** values to **decimal** or **numeric** is restricted to values of precision 17 digits only. Any **float** value less than 5E-18 (when set using either the scientific notation of 5E-18 or the decimal notation of 0.000000000000000005) rounds down to 0. This is no longer a restriction as of [!INCLUDE[ssSQL16](../../includes/sssql16-md.md)].
6270

6371
## See also
72+
6473
[ALTER TABLE &#40;Transact-SQL&#41;](../../t-sql/statements/alter-table-transact-sql.md)
6574
[CAST and CONVERT &#40;Transact-SQL&#41;](../../t-sql/functions/cast-and-convert-transact-sql.md)
6675
[CREATE TABLE &#40;Transact-SQL&#41;](../../t-sql/statements/create-table-transact-sql.md)
6776
[Data Type Conversion &#40;Database Engine&#41;](../../t-sql/data-types/data-type-conversion-database-engine.md)
6877
[Data Types &#40;Transact-SQL&#41;](../../t-sql/data-types/data-types-transact-sql.md)
6978
[DECLARE @local_variable &#40;Transact-SQL&#41;](../../t-sql/language-elements/declare-local-variable-transact-sql.md)
7079
[SET @local_variable &#40;Transact-SQL&#41;](../../t-sql/language-elements/set-local-variable-transact-sql.md)
71-
72-
80+

0 commit comments

Comments
 (0)