Use Navicat to store float type decimals

问题描述

使用nlocatStore a float type of decimals, after adding fields, others keep the default settings.

clipboard.png

Then save a piece of data, float The type of data is 129364.57. Saved results:

clipboard.png

Abandoned the decimal part, then rounded up to 129365

and then re-tested several other decimals and found that this was the case.

猜猜

1. When Lenovo learned the C language, the length of different data types was different, so guessing may not be accurate enough.

Because it is binary, so when storing decimals, there can only be 2 negative n power such as the addition of the decimal, so I will try 129364.25| ||, still not, or no fractional part, only the integer part, and also meet the rounding. ,依然不行,还是没有小数部分,只有整数部分,并且同样满足四舍五入。

So it's not a matter of precision.

2. Since there are no decimals, is there no decimal part by default?

Then redesign the table and found that the decimal part is 0, then change it to 2:

clipboard.png

and then re-test:

clipboard.png

Normal save!

Follow

google took a look at the online answer and found that there is a limit on the length of the storage, and then went to the official document to look at. The

title is very illustrative of the problem

clipboard.png

估计值. I feel that the official documentation doesn't say anything, but we know that float is estimated to have two parameters of length and precision. Then combined with the results of google, found that floatonly supports 8位, when the integer plus fractional part exceeds 8 digits, it starts 估计.

Of course, it doesn't mean that all 8 digits can be used, but there is also a range, because float uses 4 bytes, so when the value exceeds 65536( 2 to the 16th power), even if the eight digits will appear 估计 For example, we save a 65536.777, but the result is not the number after the save:

clipboard.png

summary

1. Less than 65536, the number within 8 digits is displayed normally; Exceeding 8 digits for approximate estimation (that is, the value is not allowed). 2. Greater than 65536, the number close to 8 digits starts 估计.