What's the difference between float and double?

前端 未结 2 1726
天涯浪人
天涯浪人 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 23:03

    Double

    1. Represents a 64-bit floating-point number.
    2. Has a precision of at least 15 decimal digits.

    Float

    1. Float represents a 32-bit floating-point number.
    2. precision of Float can be as little as 6 decimal digits.

    The appropriate floating-point type to use depends on the nature and range of values you need to work with in your code. In situations where either type would be appropriate, Double is preferred.

提交回复
热议问题