Click here to Skip to main content
14,383,699 members
Rate this:
Please Sign up or sign in to vote.
See more:
In my sql table I have numeric fields. When I using that in my C# back end which is the best data type to use among float, double, decimal.
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

better u can use decimal.
And u can use decimal in sql instead of numeric. There u can set how many digits after the decimal and before.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

It depends on your needs. You can not say that this numeric fields is better than others.
   
Comments
abdul wahab.o 11-May-11 7:57am
   
pls check this

http://www.codeproject.com/Questions/194654/PDTHolder-couldnot-be-found.aspx
Olivier Levrey 11-May-11 8:17am
   
I agree. Have my 5.
Sergey Alexandrovich Kryukov 11-May-11 13:50pm
   
You're a man. Tell them! My 5.
--SA
Rate this:
Please Sign up or sign in to vote.

Solution 3

Kim Togo is right. The best data type makes little sense. All these types have benefits and disadvantages.

float: takes only 4 bytes. Good if you don't need high precision numbers and if you are dealing with a lot of data.
double: takes 8 bytes. Good if you need higher precision but you need more space to store them.
decimal: takes 16 bytes. Ideal for financial and monetary calculations. But don't use this type if your storage space is limited, or if you want to do intensive mathematical calculations because your CPU will spend more time with this type (use double instead).
   
Comments
Kim Togo 11-May-11 8:26am
   
Good explanation. High 5.
Olivier Levrey 11-May-11 8:30am
   
Thank you Kim.
Sergey Alexandrovich Kryukov 11-May-11 13:51pm
   
Correct. My 5.
--SA
Rate this:
Please Sign up or sign in to vote.

Solution 4

For mapping the SQL numeric (at least the SQL Server's one) data type you should use the .NET Decimal data type, see "Mapping CLR Parameter Data"[^] at MSDN.
   
v2
Comments
Olivier Levrey 11-May-11 8:50am
   
Good point! 5+
CPallini 14-May-11 4:59am
   
Thank you.
Rick Shaub 11-May-11 9:50am
   
+5
CPallini 14-May-11 4:59am
   
Thanks.
abdul wahab.o 14-May-11 0:51am
   
+5
CPallini 14-May-11 4:59am
   
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100