SQL REAL Vs FLOAT Datatype
The floating-point numeric format is used by SQL Server's
REAL Data Types.
REAL is a single-precision float, whereas FLOAT is a double-precision float.
Floating point numbers, unlike decimal numbers, may store very big or very small numbers.
This trade-off, however, comes at the expense of precision.
Let's take a closer look at them in this tutorial and see what the differences are between float and decimal or numeric data types.
SQL REAL Datatype
The REAL data type is a floating point numeric data type that approximates a number.
Because REAL values are approximate, not all ranges of values can be represented precisely.
FLOAT is the same as REAL.
Example: A Hospital table with a 2 REAL columns we store patient's celsius and fahrenhite value .
CREATE TABLE Hospital ( Id INT IDENTITY, NameofPatient VARCHAR(100), Cel REAL, Fahr REAL ); GO INSERT INTO Hospital VALUES ('Jeeva', 36.7, 96.16); INSERT INTO Hospital VALUES ('Johnson', 37.8, 95.44); INSERT INTO Hospital VALUES ('Jancy', 36.32, 99.166); SELECT * FROM Hospital;
Output: The output of Real datatype is
SQL FLOAT Datatype
There is no fixed decimal point in floating-point numbers.
The decimal point floats, meaning it can occur anywhere in the number. As a result, it is referred to as Floating Point Numbers.
The FLOAT data type is a floating point data type that approximates a number.
Because the FLOAT value is approximate, not all values can be represented precisely.
The scientific notation is used to store the floating-point numbers in binary format.
Scientific notation is a method of expressing extremely big or small numbers. It's written in the format below.
For example, in scientific notation, 650,000,000 is expressed as 6.5 108, where 6.5 is the significand, 10 is the base, and 8 is the exponent.
Example: A table with 2 FLOAT columns.
CREATE TABLE Hospital ( Id INT IDENTITY, PatientName VARCHAR(100), CelsiusValue FLOAT, FahrenheitValue FLOAT ); INSERT INTO Hospital VALUES ('Smithi', 34.2, 97.16); INSERT INTO Hospital VALUES ('Johnson', 36.8, 96.44); INSERT INTO Hospital VALUES ('larzon', 37.23, 99.176); SELECT * FROM Hospital;
Output: The Output of Float datatype is
SQL DIFFERENCE BETWEEN REAL AND FLOAT DATATYPE
The differences between real & float datatypes are discussed in below table:-
|The Double Precision 64-bit format is used for float data. It takes up 8 bytes of memory.||Single Precision 32-bit format is the Real Data Type. It takes up 4 bytes of memory.|
|The first bit is the Sign bit, which determines whether the integer is positive or negative. The number 0 denotes a positive value. The exponent can be either 11 bits (Float) or 8 bits (Integer) (Real). The remaining spaces are used by the Significand. In the case of float data, 52 bits are used.||The first bit is the Sign bit, which determines whether the integer is positive or negative. The number 0 denotes a positive value. The exponent can be either 11 bits (Float) or 8 bits (Integer) (Real). The remaining spaces are used by the Significand. In the instance of the Real Data Type, there are 23 bits.|
|When n is between 1 and 53, the syntax for constructing a float column is float(n). The value of n is 53 by default.||The float(1) to float(23) creates a Single Precision 32-bit column, which is a Real data type. As a result, SQL Server converts it to the Real data type.|
|It isn't accurate in terms of loss.||Assuming the loss accuracy is acceptable.|