EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials MySQL Tutorial MySQL Float vs Decimal
Secondary Sidebar
MySQL Tutorial
  • Advanced
    • MySQL Formatter
    • MySQL TINYINT
    • MySQL Grant All Privileges
    • MySQL DROP TABLE
    • MySQL rename database
    • MySQL Flush Privileges
    • MySQL super Privilege
    • MySQL Character Set
    • MySQL Log File
    • MySQL Flush Log
    • Grant Privileges MySQL
    • MySQL WHILE LOOP
    • IF Statement in MySQL
    • MySQL CASE Statement
    • MySQL IF Function
    • MySQL IF EXISTS
    • MySQL UUID
    • Views in MySQL
    • MySQL Replication
    • MySQL Partition
    • Toad for MySQL
    • Navicat for MySQL
    • MySQL AES_Encrypt
    • MySQL Performance Tuning
    • MySQL Transaction
    • MySQL? sort_buffer_size
    • MySQL? Sync
    • MySQL? Query Cache
    • MySQL Collation
    • MySQL ODBC Driver
    • MySQL Partitioning
    • MySQL InnoDB
    • MySQL Float vs Decimal
    • MySQL Union vs Union All
  • Basic
    • MySQL floor
    • MySQL DESCRIBE table
    • MySQL encryption
    • Introduction to MySQL
    • Is SQL Server a Database?
    • What is MySQL
    • Is MySQL Programming Language
    • MySQL Server
    • MySQL AB
    • MySQL Community Server
    • How To Install MySQL
    • MySQL Versions
    • MySQL OpenSource
    • MySQL GUI Tools
    • MySQL Grant
    • MySQL Error 1064
    • MySQL Drop Database
    • MySQL not equal
    • MySQL SELECT INTO Variable
    • MySQL Commands
    • MySQL Operators
    • What is MySQL Schema
    • Wildcards in MySQL
    • MySQL Constraints
    • MySQL Administration
    • MySQL Data Type
    • MYSQL COMMIT
    • MySQL FORMAT
    • Timestamp to Date in MySQL
    • MySQL DATEDIFF
    • MySQL?Incremental Backup
    • MySQL JSON Data Type
    • MySQL ENUM
    • MySQL Default Port
    • Cheat Sheet MySQL
  • Queries
    • MySQL Queries
    • MySQL Query Commands
    • SELECT in MySQL
    • MySQL INSERT IGNORE
    • MySQL having
    • ORDER BY in MySQL
    • MySQL Cheat Sheet
    • MySQL ORDER BY Random
    • MySQL ORDER BY DESC
    • MySQL GROUP BY
    • MySQL GROUP BY Count
    • MySQL GROUP BY month
    • MySQL WHERE Clause
    • MySQL WITH
    • MySQL FETCH
    • MySQL DDL
    • MySQL DML
    • MySQL WHERE IN Array
    • MySQL Fetch Array
    • MySQL ISNULL
    • MySQL Index Types
    • Mysql? Export Schema
    • Amazon RDS for MySQL
    • MySQL greatest
  • Database
    • What is Data Modeling
    • What is Data Processing
    • DBMS Architecture
    • DBMS Keys
    • Careers in Database Administration
    • What is MySQL Database
    • MySQL Relational Database
    • How to Connect Database to MySQL
    • MySQL Database Repair
    • RDBMS Interview Questions
    • DBMS Interview Questions
  • Functions
    • MySQL Function
    • MySQL Aggregate Function
    • MySQL String functions
    • MySQL Date Functions
    • MySQL Window Functions
    • MySQL Math Functions
    • MySQL Boolean
    • Cursor in MySQL
    • Condition in MySQL
    • MySQL BETWEEN
    • Insert in MySQL
    • MySQL IFNULL()
    • MySQL TIMESTAMPDIFF()
    • MySQL COALESCE()
    • MySQL count()
    • MIN() in MySQL
    • MySQL Numeric
    • MySQL field()
    • MySQL FIND_IN_SET()
    • MySQL avg()
    • MySQL MAX() Function
    • MySQL BIN()
    • MySQL Concat
    • MySQL DECODE()
    • MySQL REGEXP_REPLACE()
    • MySQL Asynchronous
    • MySQL innodb_buffer_pool_size
    • MySQL key_buffer_size
    • MySQL TRUNCATE()
    • MySQL ROW_NUMBER()
    • NOT in MySQL
    • MySQL IN Operator
    • LIKE in MySQL
    • ANY in MySQL
    • MySQL NOT IN
    • MySQL CHECK Constraint
    • MySQL DISTINCT
    • MySQL ALL
    • MySQL Union
    • MySQL UNION ALL
    • MySQL EXISTS
    • MySQL ON DELETE CASCADE
    • MySQL REGEXP
    • MySQL Index
    • MySQL Add Index
    • MySQL REINDEX
    • MySQL UNIQUE INDEX
    • MySQL Clustered Index
    • MySQL? InnoDB Cluster
    • Table in MySQL
    • ALTER TABLE MySQL
    • MySQL Temporary Table
    • MySQL Clone Table
    • MySQL Repair Table
    • MySQL Lock Table
    • MySQL Optimize Table
    • TRUNCATE TABLE MySQL
    • MySQL Table Dump
    • MySQL Update Set
    • MySQL ALTER TABLE Add Column
    • MySQL RANK()
    • MySQL CTE
    • MySQL LAG()
    • MySQL GROUP_CONCAT()
    • MySQL EXTRACT()
    • MySQL REPLACE
    • MySQL AUTO_INCREMENT
    • MySQL SYSDATE()
    • MySQL NULLIF()
    • MySQL Substring
    • MySQL SUBSTRING_INDEX()
    • MySQL LOWERCASE
    • MySQL Row
    • MySQL NOW
    • MySQL CEIL
    • MySQL Alias
    • MySQL Trigger
    • MySQL SHOW Triggers
    • MySQL UPDATE Trigger
    • MySQL DELETE Trigger
    • MySQL AFTER UPDATE Trigger
    • MySQL Stored Procedure
    • ROLLUP in MySQL
    • MySQL? INSTR()
    • MySQL Subquery
    • MySQL Timestamp
    • MySQL? Hour()
    • MySQL MOD()
    • MySQL DATE_FORMAT()
    • ALTER Column in MySQL
    • MySQL Rename Column
    • MySQL Interval
    • MySQL CURDATE
    • MySQL BIT
    • MySQL Binlog
    • MySQL Average
    • MySQL TEXT
    • MySQL SHOW
    • MySQL Offset
    • MySQL Timezone
    • mysql_real_escape_string
    • MySQL Datetime
    • MySQL DATE_SUB()
    • MySQL FULLTEXT
    • MySQL DATE_ADD()
    • MySQL sum()
    • MySQL Merge
    • MySQL BigInt
    • MySQL ROUND
    • MySQL VARCHAR
    • MySQL Decimal
    • MySQL Limit
    • MySQL today()
    • MySQL WEEKDAY
    • MySQL Split
    • MySQL Create Function
    • MySQL BLOB
    • MySQL encode()
    • MySQL Primary Key
    • MySQL Foreign Key
    • Unique Key in MySQL
    • MySQL Drop Foreign Key
    • MySQL DROP TRIGGER
    • MYSQL Database
    • Delete Database MySQL
    • MySQL Root
    • MySQL Root Password
    • MySQL Client
    • MySQL Users
    • MySQL?User Permissions
    • MySQL add user
    • MySQL List User
    • MySQL Show Users
    • MySQL User Password
    • MySQL?Cardinality
    • MySQL Workbench
    • MySQL Backup
    • MySQL REVOKE
    • MySQL Dump
    • MySQL Cluster
    • MySQL Partitioning
    • MySQL Full Text Search
    • MySQL Admin Tool
    • MySQL Export Database
    • MySQL Export to CSV
  • Joins
    • Joins in MySQL
    • MySQL Outer Join
    • Left Outer Join in MySQL
    • MySQL Self Join
    • Natural Join in MySQL
    • MySQL DELETE JOIN
    • MySQL Update Join
    • MySQL Cross Join
  • Interview Questions
    • MySQL Interview Questions

Related Courses

MS SQL Certification Courses

Oracle Certification Courses

PL/SQL Certification Courses

MySQL Float vs Decimal

MySQL Float vs Decimal

Difference Between MySQL Float vs Decimal

MySQL provides the different types of data types to the user, the float and decimal are data types which are provided by MySQL. By using float data type we can represent the approximate numeric value, in MySQL float data types four bytes are used to store the single-precision value and eight bytes are used to store the double-precision values. On the other side, we have a decimal data type that comes under the numeric data types; we can use DEC as a decimal. Normally decimal is used to store the fixed value into the database. In decimal, we need to define the decimal point precision and float data types there is no need to specify the precision point.

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,768 ratings)

Head to Head Comparison between MySQL Float vs Decimal  (Infographics)

Below are the top 5 differences between MySQL Float vs Decimal:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

MySQL-Float-vs-Decimal-info

Key Differences between MySQL Float vs Decimal

Now let’s see what is the key difference between the float and decimal data types in MySQL as follows.

  • Basically floating and decimal data types are the same; this is confusion in between the float and decimal. This similarity of float and decimal data type is based on mathematics. But the key difference between them is memory and precision.
  • Confusion may cause floating-point numbers that are summarised and not put away as careful exact values. A floating-point value as written in a SQL statement may not be equivalent to the internal representation of an SQL statement. Endeavors to treat floating-point numbers as accurate in correlations may prompt issues. They are likewise dependent upon the stage of execution conditions. The FLOAT and DOUBLE data types are dependent upon these issues. For DECIMAL sections, MySQL performs activities with an accuracy of 65 decimal digits, which ought to tackle most basic incorrectness issues.
  • The DECIMAL data types are utilized to store definite numeric values. This is also called “Fixed-Point” or “Exact Value” Types and commonly utilized when it is critical to save precision points with exact value, for instance putting away the financial information like item cost. In MySQL, NUMERIC is executed as DECIMAL.
  • While pronouncing a DECIMAL or NUMERIC segment, the accuracy and scale can be determined, as DECIMAL (P,S) or NUMERIC(P,S), where P is the exactness and S is the scale. The accuracy indicates the greatest number of digits (counting the digits after the decimal point) that can be put away in the section, though the scale addresses the number of digits that can be put away after the decimal point. For instance, the value DECIMAL (8, 2) segment can store any worth with eight digits and two decimals for example in the range from – 222222.22 to 222222.22.
  • In other words, we can say that the decimal data type has a higher precision point and basically is used in financial software to avoid the rounding error in mathematics.  but the performance of the decimal type is slow as compared to the float data type. But one more important thing about the decimal is that it provides the 100 % correct representation of numbers and the other side float data types cannot provide the accurate representation of numbers even if numbers are in a specified format. Basically, the float data type is used in the graphic libraries.
  • Now let’s see the different examples of float and decimal data types to understand the more key difference between them by using MySQL statement as follows.

Example

First, we need to create a new table by using the following table as follows.

create table sample_F_D (sample_id int, Sample_Float float, Sample_Decimal decimal (4,2));

Explanation: By using the above statement, we created a new table name sample_F_D with different attributes such as sample_id with the integer data type, Sample_Float with the float data type, and Sampl_Decimal with decimal data type, and here also we specify the precision point as shown in the above statement. The final out of the above statement we illustrate by using the following screenshot as follows.

1

Now insert some value to identify the basic difference between the float and decimal data type.

Insert into sample_F_D(sample_id, Sample_Float, Sample_Decimal)  values(1, 2.1, 2.1), (2, 2.1, 2.1), (3, 2.1, 2.1) ;

Explanation: See here we use to insert into a statement to insert the floating and decimal value into the sample table.

Now see inserted records as follows.

select * from sample;

Explanation: In the above statement we use the select statement to display the rows from the sample table. It shows the floating number as well as the decimal number. The final out of the above statement we illustrate by using the following screenshot as follows.

2

Now perform the sum of both columns and see the difference between them as follows.

select sum(Sample_Float), sum(Sample_Decimal) from sample;

Explanation: After execution of the above statement the difference between float and decimal as shown in the below screenshot as follows.

3

The final output is different; notice here the Sample_Deciamal column is more precise.

MySQL Float vs Decimal  Comparison Table

Now let’s see the comparison table of float and decimal data types on MySQL as follows.

Float Decimal
Float data types are used to store the approximate precision point. In decimal data type, we can store the exact and same precision point.
We can make the changes in the floating-point number after the decimal point In decimal data type, we can make such kinds of changes.
In float data type actually, there is no need to define the precision point. When we specify the float data type to store the 6 digits then it is capable to store the 25.32 and 43.365 In decimal data type, we need to define precision points. For example, 25.32 and 45.364 should use decimal precision points.
By default range of floating data type is 24 places By default, the range of decimal data types corresponds to one byte.
Basically floating data type is a single-precision that means it uses the 32-bit floating-point data type. In decimal data type, we can use 128-bit floating-point data type.

Conclusion

We hope from this article you learn the MySQL float vs decimal. From the above article, we have learned the float vs decimal in mysql and we also see different examples of MySQL float vs decimal. From this article, we learned how and when we use the MySQL float vs decimal.

Recommended Articles

This is a guide to MySQL Float vs Decimal. Here we also discuss the MySQL Float vs Decimal key differences with infographics and comparison table. You may also have a look at the following articles to learn more –

  1. MySQL vs SQLite
  2. Back End Programming Languages
  3. MySQL Table Dump
  4. SQLite Data Types
Popular Course in this category
MySQL Training Program (12 Courses, 10 Projects)
  12 Online Courses |  10 Hands-on Projects |  92+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

MS SQL Training (16 Courses, 11+ Projects)4.9
Oracle Training (14 Courses, 8+ Projects)4.8
PL SQL Training (4 Courses, 2+ Projects)4.7
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more