Search code examples
c#var

difference between float and double data type


How can a float variable be stored in a double variable?

How to remove the compiler error in the following command?

float numb;
numb = 22.54;

Solution

  • There are two main differences in float and double. Those are size and precision.

    Float - 7 digits of precision(32 bit) and 4 bytes Ex:- 0.1234567

    Double- 15 digits of precision (64 bit) and 8 bytes Ex:- 0.123456789123456

    You can store float value in a double variable like this

    double numb;
    float numb2 = 22.5F;
    numb = numb2;
    
    output -> 22.5