The FLOAT
data type is an approximate number with floating point data.
FLOAT
value is approximate which means not all values can be represented exactly.
FLOAT(24)
is identical to REAL.
A table with 2 FLOAT
columns.
CREATE TABLE DemoTable
(
Id INT IDENTITY,
PatientName VARCHAR(100),
Celsius FLOAT,
Fahrenheit FLOAT
);
GO
INSERT INTO DemoTable VALUES ('Harold Smith', 36.2, 97.16);
INSERT INTO DemoTable VALUES ('Robert Johnson', 35.8, 96.44);
INSERT INTO DemoTable VALUES ('Janice Lopez', 37.32, 99.176);
INSERT INTO DemoTable VALUES ('Kelly Wilson', 35.89, 96.602);
INSERT INTO DemoTable VALUES ('Grace Taylor', NULL, NULL);
GO
SELECT * FROM DemoTable;
GO
DROP TABLE DemoTable;
GO
Id | PatientName | Celsius | Fahrenheit |
---|---|---|---|
1 | Harold Smith | 36.2 | 97.16 |
2 | Robert Johnson | 35.8 | 96.44 |
3 | Janice Lopez | 37.32 | 99.176 |
4 | Kelly Wilson | 35.89 | 96.602 |
5 | Grace Taylor | NULL | NULL |
Syntax of FLOAT.
FLOAT(number)
number
-- optional, number of bits between 1 and 53 used to store the mantissa of a float number. This also defines the precision and storage size used. Default is 53.
The storage used by float depends on the precision and the number of bits value:
Number of Bits | Precision | Storage (bytes) |
---|---|---|
1-24 | 7 digits | 4 |
25-53 | 15 digits | 8 |
FLOAT(24)
and REAL
values are identical.
CREATE TABLE DemoTable
(
MyFloat FLOAT(24),
MyReal REAL
);
GO
INSERT INTO DemoTable VALUES (1899.982, 1899.982);
GO
SELECT * FROM DemoTable;
GO
DROP TABLE DemoTable;
GO
MyFloat | MyReal |
---|---|
1899.982 | 1899.982 |