为了获得最佳存储效果,你应该尽量在所有情况下使用最精确的类型。例如,如果一个整数列用于存储范围从 1 到 99999 的值,MEDIUMINT UNSIGNED 是最合适的类型。在能够表示所需所有值的类型中,该类型使用的存储空间最少。For optimum storage, you should try to use the most precise type
in all cases. For example, if an integer column is used for values
in the range from 1 to
99999, MEDIUMINT UNSIGNED is
the best type. Of the types that represent all the required
values, this type uses the least amount of storage.
所有使用 DECIMAL 列进行的基本计算(+、-、* 和 /)都具有 65 位十进制数字的精度。请参见 第 13.1.1 节,“数值数据类型语法”。All basic calculations (+,
-, *, and
/) with DECIMAL
columns are done with precision of 65 decimal (base 10) digits.
See Section 13.1.1, “Numeric Data Type Syntax”.
如果精确度不是特别重要,或者速度是最优先考虑的,DOUBLE类型可能已经足够。对于高精度,你总是可以转换为存储在BIGINT中的定点类型。这样你就可以用 64 位整数进行所有计算,然后在必要时将结果转换回浮点值。If accuracy is not too important or if speed is the highest
priority, the DOUBLE type may be
good enough. For high precision, you can always convert to a
fixed-point type stored in a
BIGINT. This enables you to do all
calculations with 64-bit integers and then convert results back to
floating-point values as necessary.