Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
5.00/5 (1 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

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.
 
Share this answer
 
It depends on your needs. You can not say that this numeric fields is better than others.
 
Share this answer
 
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
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).
 
Share this answer
 
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
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.
 
Share this answer
 
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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900