且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL大于或等于运算符正在忽略其等于义务

更新时间:2023-02-10 16:58:47

请牢记float在精度方面是有缺陷的数据类型.如果将12表示为浮点数,则会得到11.99999999999998或类似内容.

keep in mind that float is a flawed data type when it comes to precision. If you represent 12 as float, you will get 11.99999999999998 or something.

'38.03'可以转换为十进制或其他更精确的数据类型(取决于RDBMS,在这里我很一般),它将不同于浮点值.

'38.03' can be converted to decimal, or other data type that is more precise (depending on RDBMS, I am being general here), and it will differ from the float value.

浮点数是32位,精度低. Double是64位数据类型,效果更好.在某些系统中,十进制数据类型是128位数字数据类型,用于存储非常精确的数值,通常用于表示货币.

float is 32 bit, low precision. Double works a lot better, being 64 bit data type. Decimal data type in some systems are 128 bit numeric data types for storing very precise numeric values, and is usually used for denominating money.

并且,跳过使用=运算符比较float值的习惯.浮点数用于近似和快速计算,并且只有与范围的比较才可以用于检查float的值.基本上对每个系统都有效.

And, skip the habit of comparing using the = operator, of float values. Floats are used for approximate and fast calculations, and only comparison with a range is acceptable for checking the value of a float. That's valid for basically every single system.