Float and double are both widely used data types in programming that have the ability to store decimal or floating-point numbers. The only difference between them is the precision.
A float is a 32-bit IEEE 754 single-precision floating-point number.
1 bit
for the sign8 bits
for the exponent23 bits
for the value.
A float
has 7 decimal digits of precision and occupies 32 bits
.
A double is a 64-bit IEEE 754 double-precision floating-point number. 1 bit
for the sign, 11 bits
for the exponent, and 52 bits
for the value. A double has 15 decimal digits of precision and occupies a total of 64 bits
.
Below is example for further clarification. See how float
cannot store the entire value since it has less precision than double
.
using System;class HelloWorld{static void Main(){float f = 1F/3; //1F is float value of 1double d = 1D/3; // 1D is 1 stored as a doubleConsole.WriteLine("float: {0} double: {1}", f, d);}}
Free Resources