Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent datatype of SQL Server's Numeric in C#

In SQL Server we can write data AS Numeric(15,10) .. what will the equivalent of this in C#?

I know that Numeric's equivalent is Decimal but how to represent Numeric(15,10)?

like image 908
mcUser Avatar asked Jul 21 '11 06:07

mcUser


People also ask

What is numeric data type in SQL Server?

In SQL, numbers are defined as either exact or approximate. The exact numeric data types are SMALLINT , INTEGER , BIGINT , NUMERIC(p,s) , and DECIMAL(p,s) . Exact SQL numeric data type means that the value is stored as a literal representation of the number's value.

What is the equivalent of numeric in C#?

There isn't a direct equivalent, in that there are no built-in . NET types which allow you to specify the precision/scale explicitly as far as I'm aware. There's no fixed-point type like NUMERIC. decimal and double are the common floating point types in .

Which SQL data type is used to contain numeric values?

INTEGER or INT The INTEGER data type accepts numeric values with an implied scale of zero. It stores any integer value between the range 2^ -31 and 2^31 -1.


2 Answers

There isn't a direct equivalent, in that there are no built-in .NET types which allow you to specify the precision/scale explicitly as far as I'm aware. There's no fixed-point type like NUMERIC.

decimal and double are the common floating point types in .NET, with decimal implementing decimal floating point (like NUMERIC in T-SQL) and double implementing binary floating point behaviour (like FLOAT and REAL in T-SQL). (There's float as well, which is a smaller binary floating point type.)

You should choose between decimal and double based on what values you're going to represent - I typically think of "man-made", artificial values (particularly money) as being appropriate for decimal, and continuous, natural values (such as physical dimensions) as being appropriate for double.

like image 166
Jon Skeet Avatar answered Oct 03 '22 03:10

Jon Skeet


Try looking at this site as a guide to the data type mappings. As far as the precision and length, you control that yourself using format specifiers

like image 34
Icemanind Avatar answered Oct 03 '22 03:10

Icemanind