MySQL:(产品)价格的首选列类型?

标签 mysql

在 MySQL 中,存储产品价格(或一般货币)的首选列类型是什么?谷歌知道我经常使用 DECIMAL of FLOAT,但我想知道哪个更好。

我存储的价格范围是 0.01 到 25.00。当然更高的值也是可能的。 (注意:我不是要求复制意大利面代码,我只是为您提供更多信息,可以帮助您形成更完整的答案)。

谢谢

最佳答案

十进制是我会使用的

The basic difference between Decimal/Numeric and Float : Float is Approximate-number data type, which means that not all values in the data type range can be represented exactly. Decimal/Numeric is Fixed-Precision data type, which means that all the values in the data type reane can be represented exactly with precision and scale.

Converting from Decimal or Numeric to float can cause some loss of precision. For the Decimal or Numeric data types, SQL Server considers each specific combination of precision and scale as a different data type. DECIMAL(4,2) and DECIMAL(6,4) are different data types. This means that 11.22 and 11.2222 are different types though this is not the case for float. For FLOAT(6) 11.22 and 11.2222 are same data types.

关于MySQL:(产品)价格的首选列类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1796334/

相关文章:

php - 填写先前数据库条目中的表单字段 - php

MySQL 在插入到 table1 时自动将一行插入到 table2

MySQL 查询我所有(接受的) friend 的列表

php - 基本 PHP/mySQL 问题...循环遍历表中的每一行

php - 将长文本发送到 mysql 数据库?

mysql - 时间戳和mysql

php - yii框架中数据库迁移错误

php - 添加类似查询的搜索时,查询结果发生变化

mysql - 我怎样才能解决 "Collation is not valid for CHARACTER SET ' latin 1'"?

mysql - mysqldump 抛出错误代码 (1054)