1. 程式人生 > >MYSQL浮點數float精度問題

MYSQL浮點數float精度問題

遇到mysql設計的是6位float數經緯度,賦值的時候,明明是準去的資料insert進去,但是卻發現,資料自動變了,精度明顯丟失。檢視官方文件才發現

https://dev.mysql.com/doc/refman/5.7/en/problems-with-float.html

確實是有問題,但是mysql已經有另外的方式解決了這個問題,那就是decimal

Floating-point numbers sometimes cause confusion because they are approximate and not stored as exact values. A floating-point value as written in an SQL statement may not be the same as the value represented internally. Attempts to treat floating-point values as exact in comparisons may lead to problems. They are also subject to platform or implementation dependencies. The 

FLOAT and DOUBLE data types are subject to these issues. For DECIMAL columns, MySQL performs operations with a precision of 65 decimal digits, which should solve most common inaccuracy problems.

大體就是這個意思