MySQL 在mysql中存储负值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8644196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:09:59  来源:igfitidea点击:

storing negative value in mysql

mysqldecimalmysql5negative-number

提问by Hafiz

How can I store negative value in mysql decimal? I have data from DMS to Decimal having negative values, so it is decimal and negative. So what can I use to store such value?

如何在mysql十进制中存储负值?我有从 DMS 到 Decimal 的数据有负值,所以它是小数和负数。那么我可以用什么来存储这样的值呢?

回答by gbn

Use MySQL DECIMALtype?

使用 MySQL DECIMAL类型?

Standard SQL requires that DECIMAL(5,2) be able to store any value with five digits and two decimals, so values that can be stored in the salary column range from -999.99 to 999.99

标准 SQL 要求 DECIMAL(5,2) 能够存储任何五位数和两位小数的值,因此可以存储在薪水列中的值范围从 -999.99 到 999.99

回答by Rossitten

In case you want to store a negative integer- (INT) will work nicely, unless it's not UNSIGNED.

如果您想存储一个负整数- ( INT) 会很好地工作,除非它不是 UNSIGNED。

https://dev.mysql.com/doc/refman/8.0/en/integer-types.html

https://dev.mysql.com/doc/refman/8.0/en/integer-types.html

In case you want to store a negative decimal- (DECIMAL) is the way to go, as GBN mentioned above.

如果您想存储负小数- (DECIMAL)是要走的路,如上面提到的 GBN。

https://dev.mysql.com/doc/refman/5.7/en/precision-math-decimal-characteristics.html

https://dev.mysql.com/doc/refman/5.7/en/precision-math-decimal-characteristics.html