Difference between Decimal, Float and Double in .Net
It is a floating binary point type variable. Which means it represents a number in it’s binary form. Float is a single precision 32 bits(6-9 significant figures) data type. It is used mostly in graphic libraries because of very high demand for processing power, and also in conditions where rounding errors are not very important.
It is also a floating binary point type variable with double precision and 64 bits size(15-17 significant figures). Double are probably the most generally used data type for real values, except for financial applications and places where high accuracy is desired.
It is a floating decimal point type variable. Which means it represents a number using decimal numbers (0-9). It uses 128 bits(28-29 significant figures) for storing and representing data. Therefore, it has more precision than float and double. They are mostly used in financial applications because of their high precision and easy to avoid rounding errors.
Comparison between Float, Double and Decimal on the Basis of :
- No. of Bits used –
- Float uses 32 bits to represent data.
- Double uses 64 bits to represent data.
- Decimal uses 128 bits to represent data.
- Range of values –
- The float value ranges from approximately ±1.5e-45 to ±3.4e38.
- The double value ranges from approximately ±5.0e-324 to ±1.7e308.
- The Decimal value ranges from approximately ±1.0e-28 to ±7.9e28.
- Precision –
- Float represent data with single precision.
- Double represent data with double precision.
- Decimal has higher precision than float and Double.
- Accuracy –
- Float is less accurate than Double and Decimal.
- Double is more accurate than Float but less accurate than Decimal.
- Decimal is more accurate than Float and Double.
For documentation related to Float , double and Decimal, kindly visit here.
Attention reader! Don’t stop learning now. Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.
Learn all GATE CS concepts with Free Live Classes on our youtube channel.