Reputation: 12512
It's a quick question, but I can't seem to be able to find the right answer... I need to store numeric values in mySQL table. Some can be positive, some negative. The largest can be 100 the smallest -100. What is the best data type I should use? VARCHAR? INT works only with positives, right?
Upvotes: 0
Views: 65
Reputation: 115630
INT
types work for both positive and negative.
You can use the TINYINT SIGNED
to store integer values between -128
and +127
.
If you want to store not only integers but numbers with fractional parts, you can use either FLOAT
or DECIMAL(m.n)
. With DECIMAL(5,2)
you could store any value from -999.99
to +999.99
(5 digits, 2 after the decimal point).
Upvotes: 2
Reputation: 64429
Use a tinyint
http://dev.mysql.com/doc/refman/5.0/en/integer-types.html
Upvotes: 1
Reputation: 2062
You want to use TINYINT http://dev.mysql.com/doc/refman/5.0/en/integer-types.html
Upvotes: 1
Reputation: 14834
INT works with negative numbers as well as long as you don't specify UNSIGNED. TINYINT (-128 to 127) would be the best choice for your range of values.
Upvotes: 0