MySQL :(产品)价格的首选列类型? [英] MySQL: preferred column type for (product) prices?

查看:218
本文介绍了MySQL :(产品)价格的首选列类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MySQL中,用于存储产品价格(或一般货币)的首选列类型是什么? Google得知我经常使用DECIMAL FLOAT,但我不知道哪种更好.

In MySQL, what is the preferred column type for storing a product's price (or currencies in general)? Google learned me DECIMAL of FLOAT is often used, but I wonder which one is better.

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

I'm storing prices ranging from 0.01 to 25.00. Of course higher values could also be possible. (Note: I'm not asking for copy-pasta code, I'm just giving you more information which could help you form a more complete answer).

谢谢

推荐答案

十进制是我要使用的那个

Decimal is the one I would use

之间的基本区别 十进制/数字和浮点数:浮点数为 近似数字数据类型,其中 表示并非数据中的所有值 类型范围可以准确表示. 十进制/数字是固定精度的 数据类型,这意味着所有 数据类型reane中的值可以是 精确地表示,并且 规模.

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.

从十进制或数字转换为 浮动可能会导致一些损失 精确.对于十进制或数字 数据类型,SQL Server会考虑每种 精度和 缩放为其他数据类型. DECIMAL(4,2)和DECIMAL(6,4)是 不同的数据类型.这意味着 11.22和11.2222是不同的类型,但float并非如此. 对于FLOAT(6),分别为11.22和11.2222 相同的数据类型.

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 :(产品)价格的首选列类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆