Float Data Type
The Float data type is used to store floating point numbers that are not fixed/exact. This means that the float data type does not store the exact values, rather, it stores the approximate value of the stored number.
Syntax:
FLOAT(precision)
Float Data Type Example
-- Create the table
CREATE TABLE STUDENT(
Name VARCHAR(20),
Result FLOAT(5)
);
-- Insert sample data
INSERT INTO STUDENT(Name, Result) VALUES ('John', 98.75000);
INSERT INTO STUDENT(Name, Result) VALUES ('Alice', 87.50000);
Output:
Explanation: The SQL script creates a table named “STUDENT” with columns “Name” and “Result” of data type FLOAT(5). Sample data is inserted into the table with names “John” and “Alice” along with their corresponding results. The FLOAT(5) data type allows for storing approximate floating-point numbers with up to 5 digits.
What is the Difference Between Numeric, Float, and Decimal in SQL server?
The SQL Server has a variety of data types to store data. These data types can accompany several forms like string, integer, double, date, time, etc. Therefore selecting the appropriate data structure is crucial for maintaining the data accuracy and optimizing the system’s performance.
This article delves into the fundamentals of three crucial data types: Numeric, Float, and Decimal.