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)
?
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.
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 .
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.
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
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With