Im inserting Data into a database, they have a decimal and a negative number, is there a way to the DataType Decimal into negative numbers or is there another data type I can use?
3 Answers
The decimal datatype can store negative numbers as well. So to answer your question, yes you can use the decimal datatype to store negative decimal numbers.
Here is some proof:
create table NegativeDecimal
(
somedec decimal(10, 4) not null
)
go
insert into negativedecimal
select -12.3
union all
select 16.4
go
select *
from NegativeDecimal
somedec
---------------------------------------
-12.3000
16.4000
(2 row(s) affected)
EDIT: This is provided you are using SQL Server. Please specify your RDBMS.
You don't state which DBMS you're using, but on MySQL at least, negatives are supported in decimals:
mysql> create table x (x decimal(5,2));
Query OK, 0 rows affected (0.06 sec)
mysql> insert into x (x) values (-3.14);
Query OK, 1 row affected (0.00 sec)
mysql> select * from x;
+-------+
| x |
+-------+
| -3.14 |
+-------+
1 row in set (0.00 sec)
For math definition decimal number could be positive or negative and the data structures know that, for the same reason is not a special type for negative or positive numbers