Differences between decimal (numeric), float, and real data types in SqlServer [

Source: Internet
Author: User
Decimal (numeric) is synonymous with precision storage of float and real. decimal data types can store up to 38 numbers, and all numbers can be placed on the right of the decimal point. The decimal data type stores an accurate (accurate) numeric expression, not nearly stored. Two types of columns, variables, and parameters that define decimal

Decimal (numeric) is synonymous with precision storage of float and real. decimal data types can store up to 38 numbers, and all numbers can be placed on the right of the decimal point. The decimal data type stores an accurate (accurate) numeric expression, not nearly stored. Two types of columns, variables, and parameters that define decimal

Decimal (numeric) is synonymous and used to precisely store values.

Float and real cannot accurately store values.


DecimalThe data type can store up to 38 numbers, and all numbers can be placed on the right of the decimal point.DecimalThe data type stores an accurate (accurate) numeric expression, and does not store approximate values.

DefinitionDecimalThe columns, variables, and parameters are as follows:

  • P indicates the sum of the numbers on the left and right of the decimal point, excluding the decimal point. For example, 123.45, p = 5, s = 2.

    Specifies the number of numbers that can be controlled by precision or object.

  • S

    Specify the number of decimal places or numbers to the right of the decimal point.

    P and s must follow the following rules: 0 <=S<=P<= 38.

NumericAndDecimalThe default maximum precision of the data type is 38. In Transact-SQL,NumericAndDecimalThe data type is functionally equivalent.

When the data value must be precisely stored as specifiedDecimalData Type to store numbers.

Float and real data

FloatAndRealData types are called similar data types. In terms of approximate numeric data types,FloatAndRealThe use of data follows the IEEE 754 standard.

The approximate numeric data type does not store the exact values specified for most numbers. They only store the approximate values of these values. In many applications, the tiny difference between the specified value and the stored value is not obvious. However, sometimes these differences are worth noting. BecauseFloatAndRealThis approximation of the Data Type requires precise numerical states, such as in financial applications, in operations that require rounding, or in operations that require equivalent verification, these data types are not used. UseInteger,Decimal,MoneyOrSmallmoneData type.

In the WHERE clause Search Condition (especially the = and <> operators), avoid usingFloatOrRealColumn. Best PracticeFloatAndRealColumn> or <comparison.

The IEEE 754 specification provides four rounding modes: Rounding to the nearest value, rounding up, downloading, and rounding to zero. Microsoft? SQL Server? Use top rounding. All values must be accurate to the specified precision, but small floating point values may change. Because the binary representation of floating point numbers can use any of the many valid rounding rules, it is impossible for us to reliably quantify a floating point value.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.