Difference between Decimal, Float and Double in mysql

Difference between Decimal, Float and Double in mysql

Decimal, Float and Double All these three Types, can be specified by the following Parameters (size, d). Where size is the total size of the String, and d represents precision. E.g To store a Number like 1234.567, you will set the Datatype to DOUBLE(7, 3) where 7 is the total number of digits and 3 is the number of digits to follow the decimal point.

Decimal and Double is similar in declaration and functioning. But there is a big difference between floating point values and decimal (numeric) values. We use DECIMAL data type to store exact numeric values do not required precision values to declare decimal values, it is exact and accurate values. A Decimal type can store a Maximum of 65 Digits values, with 30 digits after decimal point.

FLOAT and DOUBLE, both represent floating point numbers. FLOAT is better for scientific types of calculations where extra precision only helps.float is a 32bit single precision Floating Point number.while double is a 64bit double precision floating point number. A precision from 24 to 53 results in an 8-byte double-precision DOUBLE column. FLOAT is accurate to approximately 7 decimal places, and DOUBLE upto 14 decimal places.

DECIMAL is best for monetary nature because you can specify the exact precision of a number.Decimal can 100% accurately represent any number within the precision of the decimal format, whereas Float and Double, cannot accurately represent all numbers, even numbers that are within their respective formats precision. we have create a table decimal_float with two column dml decimal(10,2) and flt float(10,2). Now we have insert the record in the table with two precision.

1

2

insert into decimal_float values(64.83,74.88);

insert into decimal_float values(25.99,45.99);

Now we have select float column values with 10 precision. you can see that 64.83 and 74.88 isn’t actually being stored to an exact precision. we can see the result.

1

2

3

//MySQL query to fetch the record from decimal_float

SELECT(1.0000000000*flt)

FROM decimal_float;

MySql query Result

Now we have select float column values with 7 precision, and response result is.

1

2

3

4

//MySQL query to fetch the record from decimal_float

SELECT(1.0000000*flt)

FROM decimal_float;

MySql query Result

Now we have select decimal column values with 10 precision. but you know that decimal is store exact values with two precision.so it gives exact values with 10 precision. we can see the result.