MYSQL Difference between FLOAT and DOUBLE

3

What is the difference between fields type Float and Double in MySQL ? In addition to the difference of being able to cover Double bigger numbers than those that can store Float . Are there any other differences?

For example, if I am going to use it to store the price of a product and I know that my products will always cost between 0 and 10,000, which one should I use?

    
asked by José Alexis Cruz Solar 14.05.2018 в 06:23
source

2 answers

1

Inside MySQL (I do not know about other managers)

  • Float is for simple preset in a range of 4 bytes
  • Double is for a preset range of 8 bytes
  • Besides that, FLOAT allows a precision from 0 to 23 while DOUBLE manages it from 24 to 53

      

    In the case of DOUBLE, it allows an entry of signed values from   -1.7976931348623157E + 308 to -2.2250738585072014E-308, 0, and without sign from 2.2250738585072014E-308 to 1.7976931348623157E + 308

    As you can notice, the storage capacity of a data of this type is gigantic but it will depend a lot on the reality of the qualities of your hardware

      

    In the case of FLOAT it goes from -3.402823466E + 38 to -1.175494351E-38
      and without sign from 1.175494351E-38 to 3.402823466E + 38

    UPDATE

    However, when reviewing your own documentation, it will be more optimal to use decimal, as it only asks for this: decimal (a, b) decimal (5, 2) where a or 5 is the length that will occupy and b or 2 is the number of decimals that will accept

    The detail with DOUBLE and FLOAT is that they are not saved with certainty by the architecture of a PC, therefore they do not store the values in a reliable way.

    DECIMAL surpasses them because the values are stored as a kind of character string representation, which provides greater certainty than with the previous data

    Since what you try to save and how well I did the observation @ Gbianchi is price amounts it will be better to use decimal

        
    answered by 14.05.2018 / 06:50
    source
    0

    If you review the MySQL manual to store pricing information, we recommend Decimal (m, n) .

    Where m is the field total and n is the number of decimals.

        
    answered by 14.05.2018 в 07:16