Can you point me to a reference that shows what how to convert a data type of double in C#.net 2008 and to sql server 2008 r2 that are size number(18,0).
Basically I take the sql server 2008 r2 column that is size number(18,0) and make it a Double in a C#.net 2008 application. I then want to pass the C#.net datatype double back to to sql server 2008 r2 that are size number(18,0).
Note: Basically I want to take the sql server 2008 r2 field that is size number(18,0) and work with it in the .net application and pass it back to the database as a paramter. Thus, also do you think i should use a different data type in the .net app besides a double? if so, what value do you think I should use?
VulpesPosted Aug 10, 2011, 5:47 PM
As I mentioned in your other thread, the decimal type would be suitable as it has a precision of 28 digits.
It's only drawback, is its size (16 bytes as opposed to 8 for double) and relatively slow calculation speed. However, you're unlikely to notice this unless you have thousands of calculations to perform.
As an alternative, you could use C#'s long type which can hold integers up to 9,223,372,036,854,775,807 and can therefore (just) deal with 18 digits. It corresponds to the bigint type in SQL Server. It's much more efficient for calculations than decimal and requires 8 bytes of storage.
To convert decimal to long in C# just requires a cast which, as long as the number is within long's range, will not fail at runtime:
decimal d = 9223372036854775807m; // 'm' suffix used to signify a decimal
long l = (long)d;
Console.WriteLine(l); // no error or loss of precision