Comparison between real data types

  • Hi

    I have two variables having real as data type. I am using one function and the value is coming as same in both the variables.

    Now if the value is something like 12.8 in both the variable, then sql treats them equal variables but when value is coming as 14.2607 in both, then the first variable is treated as greater than the second one.

    Can anybody help understanding the basic difference between real and float?

  • Using float and real Data

    The float and real data types are known as approximate data types. The behavior of float and real follows the IEEE 754 specification on approximate numeric data types.

    Approximate numeric data types do not store the exact values specified for many numbers; they store an extremely close approximation of the value. For many applications, the tiny difference between the specified value and the stored approximation is not noticeable. At times, though, the difference becomes noticeable. Because of the approximate nature of the float and real data types, do not use these data types when exact numeric behavior is required, such as in financial applications, in operations involving rounding, or in equality checks. Instead, use the integer, decimal, money, or smallmoney data types.

    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 convert(real,variable)

  • Can you post the code you are using?

    There is no real difference between Real and Float, except for the fact that Float lets you define the precision. The Real data type precisely calculates up to 8 digits. Float was introduced to meet SQL-92 standard.

    If the 2 fields exist on different database servers then you might have issues with the processor on each machine calculating the precision differently, as the Real data type is an approximate numeric type. You might be better off switching to the Numeric or Decimal data types.

    Chris Fitzgerald 😀

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply