Float not correct in MySQL

前端 未结 5 1746
旧时难觅i
旧时难觅i 2020-12-06 14:06

I am entering \'35444650.00\' as a float into my MySQL and it keeps reformatting to 35444648.00, any help welcome...

相关标签:
5条回答
  • 2020-12-06 14:49

    A higher precision alternative to float is DOUBLE. But looking at the example, I think the DECIMAL datatype might come in handy if the number of digits required after zero is small (around 2-4) and the number of digits before decimal is also small (around 10-12).

    0 讨论(0)
  • 2020-12-06 14:59

    A float has 6 digits of precision. Use a double to get 15 or switch to a numeric(x,y). If you're interested, check out the storage requirements for MySQL for the different data types.

    0 讨论(0)
  • 2020-12-06 15:02

    The MySQL manual claims that FLOAT, REAL, and DOUBLE PRECISION fields stores values as approximate and INTEGER, SMALLINT, DECIMAL, and NUMERIC fields stores values as exact.

    I think best bet to overcome this precision issue is to use decimal.

    Reference: http://dev.mysql.com/doc/refman/5.1/en/numeric-types.html

    0 讨论(0)
  • 2020-12-06 15:09

    Floats only have a certain level of precision, you may be going beyond how precise a float data type can be. Try using a DOUBLE instead.

    0 讨论(0)
  • 2020-12-06 15:09

    You are going past the level of precision possible. You need to define the float with more precision, i.e. "FLOAT(10,5)" would mean a float that can have 10 digits total with up to five after the decimal point.

    0 讨论(0)
提交回复
热议问题