Home > database >  Mysql float, double the difference between a decimal
Mysql float, double the difference between a decimal

Time:09-28

Built a test table, fields for a float, 4 (11), field b for double (11, 4), a is a decimal (11, 4)
1, INSERT data:
 INSERT INTO test (a, b, c) the VALUE (' 123456.888 ', '123456.888', 123456.888 ' '
)

Why the field "123456.8906" is a value?

2, INSERT data:
 INSERT INTO test (a, b, c) the VALUE (' 92345678.888 ', '92345678.888', 92345678.888 ' '
)

Why all have changed, not add value, not equal to 11?

3, how to choose the appropriate data type, such as a decimal for accounting calculation, the float, and double, float (11, 4) brackets 11 is accuracy, precision of the mean down to 11?

CodePudding user response:

Suggest all use a decimal
Float, double the low precision of the only benefit is to take up less space

CodePudding user response:

You INSERT INSERT INTO test (a, b, c) the VALUE (' 92345678.888 ', '92345678.888', '92345678.888')
An error in my database, because you set up 11 is refers to the digits including decimal point, so it is more than 11,
Single-precision floating-point Float: when the data range within +/- 131072 (65536 x 2), Float data accuracy is correct, but beyond the scope of data is not stable,
A double and a decimal number range is bigger, so it is recommended to use a double and a decimal value type

CodePudding user response:

Your scene a decimal (m, n), if precision is not strictly select double float, float, double low accuracy, but the occupied space is small,
  • Related