推荐用于数字类型的数据类型 [英] Reccomended data type to use for numeric type

查看:133
本文介绍了推荐用于数字类型的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的sql表中,我有数字字段.当我在C#后端中使用它时,这是在float,double,decimal中使用的最佳数据类型.

解决方案

更好地,您可以使用十进制. > 而且您可以在sql中使用小数而不是数字.您可以在其中设置小数点后和小数点后的位数.


这取决于您的需要.您不能说此数字字段比其他数字字段要好.


Kim Togo是正确的. 最佳数据类型毫无意义.所有这些类型都有优点和缺点.

float:仅占用4个字节.如果您不需要高精度数字并且要处理大量数据,那就很好了.
double:占用8个字节.如果您需要更高的精度,但又需要更多空间来存储它们,那就很好了.
decimal:占用16个字节.金融和货币计算的理想选择.但是,如果您的存储空间有限,或者您要进行大量的数学计算,请不要使用此类型,因为您的CPU会花费更多时间使用这种类型(改为使用double).


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.

解决方案

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.


It depends on your needs. You can not say that this numeric fields is better than others.


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).


这篇关于推荐用于数字类型的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆