简体   繁体   English

我应该使用哪种数据类型来满足C#中的以下要求

[英]What Datatypes should i use for following requirement in C#

First I will explain the name of different properties and function that will be performed on them. 首先,我将解释将对它们执行的不同属性和功能的名称。 Afterwards you tell me which datatype should i use for them ?? 之后,您告诉我应该为它们使用哪种数据类型?

1) Gross Weight(user will enter) : Will be in quintals(weight category). 1)毛重(用户将输入):将以公担(体重类别)为单位。 For Example : 147.3800. 例如: 147.3800。

2) Less Tear(user will enter : Also be in quintals(weight category). For Example : .3800. 2)较少的撕裂(用户输入:也可以是五分制(重量类别), 例如: .3800。

3) Net Weight(Auto-Computed) : In quintals(weight category). 3)净重(自动计算):以公担为单位(重量类别)。 For Example : GrossWeight - Less Tear. 例如:毛重-更少的眼泪。

4) Rate/Quintal(user will enter) : Amount for per quintal. 4)费率/总数量(用户将输入):每5单位的数量。 For Example : 4560.55 例如: 4560.55

5) Total Amount(Auto-Computed) : For Example : NetWeight x Rate/Quintal 5)总金额(自动计算): 例如:净重x费率/位数

Now tell me the preferable data-types for above five fields in C#. 现在告诉我C#中以上五个字段的首选数据类型。

In every case you probably want to use a floating point value, which means a decision between double and decimal. 在每种情况下,您可能都想使用浮点值,这意味着要在双精度和十进制之间进行选择。

Since .NET lacks objects dealing with arbitrary-precision floating point operations, the choice is connected mostly with precision and range. 由于.NET缺少处理任意精度浮点运算的对象,因此选择大多与精度和范围有关。 Decimal has smaller range (from 10e-28 up to 7.9 x 10e28, but better precision (28-29 significant digits). Double works the other way round (range from ~10e-324 to ~10e308 and 15-16 digits). 十进制的范围较小(从10e-28到7.9 x 10e28,但精度更高(28-29个有效数字);双精度则相反(从〜10e-324到〜10e308和15-16个数字)。

For this scenario I would recommend using decimals in all cases. 对于这种情况,我建议在所有情况下都使用小数。

When possible, use decimal for money (#4 and #5) to avoid floating-point representation errors. 尽可能使用decimal表示货币(#4和#5),以避免浮点表示错误。

For physical measurements like weight, or for irrational-valued functions like sin or log , prefer double . 对于诸如体重之类的物理测量,或者对于诸如sinlog无理值函数,建议使用double

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM