What's the difference between float and double?

前端 未结 2 1714
天涯浪人
天涯浪人 2021-01-03 22:14

When I run the following code ,

NSString* s= @\"10000000.01\";
float f = [s floatValue];
double d = [s doubleValue];

if(f > 10000000)
{
    NSLog(@\"Ove         


        
2条回答
  •  不知归路
    2021-01-03 22:53

    float is 32-bit while double is 64-bit. A float has fewer significant digits than double.

    A float value doesn't store enough to hold the 10 digits of your 10000000.01.

    Also see Difference between float and double for more details. That is about C/C++ but it applies to Objective-C as well.

提交回复
热议问题