货币应该使用什么数据类型
我正在 MySQL Workbench 中创建一个数据库表。我想要创建的表是能够保存带有小数点的数字的数据。我想要保存的数据是一个货币值,其小数点为分。我已经创建了一个表,数据类型是十进制。然而,当我检查保存的数据时,数字被四舍五入,分也消失了。我想要的是它不会改变任何事情。它仍然会显示准确的值。请帮忙。
I am creating a database table in MySQL Workbench. The table I want to create is to be able to save data which is a number with a decimal point. The data I want to save is a money value which has a decimal point for the centavos. I already created a table and the data type is decimal. However, when I checked the saved data the numbers where rounded off and the centavos where gone. What I want is that it won't change anything. It will still show the exact values. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有使用过Workbench,所以我不能告诉你具体怎么做,但定义应该是DECIMAL(M,D),其中M是总位数,D是右边的总位数小数点的。因此,在您的情况下,您希望 D=2,并根据您的应用选择 M>2。如果 D 设置为 0,它会自动四舍五入你的数字(听起来这可能是你的问题)。
除此之外,我想不出它无法正确存储数据的充分理由。
I haven't used Workbench so I can't tell you exactly how to do it, but the definition should be DECIMAL(M,D) where M is the total number of digits, and D is the total number of digits to the right of the decimal. So in your case you want D=2, and choose M>2 as appropriate for your application. If D is set to 0 is it will round off your numbers automatically (sounds like that might be your problem).
Other than that I can't think of a good reason it wouldn't store the data properly.