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?
Asked
Active
Viewed 8.5k times
32
-
Column of type `numeric` or any flavour of myriad of floats available with MySQL and then simply use `INSERT INTO your_table SET your_number = '-1000.99';`, replace the SQL command with one you need of course. – N.B. Dec 27 '11 at 11:38
-
You can store either positive or negative values in Decimal columns. WHat have you tried? – ypercubeᵀᴹ Dec 27 '11 at 11:38
-
possible duplicate of : http://stackoverflow.com/questions/3760822/storing-negative-number-in-decimal-field-of-mysql-table-as-of-version-5-0-3 – xQbert Dec 27 '11 at 11:39
-
@xQbert: I'd say that doesn't apply. The other Q is about changes related over different versions, whereas this is "what type do I use" – gbn Dec 27 '11 at 11:42
-
1Possibly just some confusion over signed vs unsigned? – dash Dec 27 '11 at 11:59
-
I wrote some thing from mysql site that it doesnot deal with negative number but maybe I didn't read correctly as I was going through many things at that time. So let me try negative – Hafiz Dec 27 '11 at 16:01
2 Answers
3
In case you want to store a negative integer - (INT) will work nicely, unless it's not UNSIGNED.
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.
https://dev.mysql.com/doc/refman/5.7/en/precision-math-decimal-characteristics.html

Rossitten
- 1,140
- 1
- 16
- 34
-
*unless it's UNSIGNED. If it is an unsigned INT minimum value will be 0 – Gonzalo F S Oct 20 '22 at 09:28