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). For Example : 147.3800.
2) Le开发者_Python百科ss Tear(user will enter : Also be in quintals(weight category). For Example : .3800.
3) Net Weight(Auto-Computed) : In quintals(weight category). For Example : GrossWeight - Less Tear.
4) Rate/Quintal(user will enter) : Amount for per quintal. For Example : 4560.55
5) Total Amount(Auto-Computed) : For Example : NetWeight x Rate/Quintal
Now tell me the preferable data-types for above five fields in C#.
When possible, use decimal
for money (#4 and #5) to avoid floating-point representation errors.
For physical measurements like weight, or for irrational-valued functions like sin
or log
, prefer double
.
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. 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).
For this scenario I would recommend using decimals in all cases.
精彩评论