float f2,f1 = 123.125;
它们之间有什么不同?objective c float numer conversion
float f1 = 123.125,f2;
,如果我写的代码为
float f1,f2 = 123.125
程序将有不同的结果
这里是完整的程序
float f2,f1 = 123.125;
//float f1 = 123.125,f2;
int i1,i2 = -150;
i1 = f1; //floating to integer
NSLog(@"%f assigned to an int produces %i",f1,i1);
f1 = i2; //integer to floating
NSLog(@"%i assigned to a float produces %f",i2,f1);
f1 = i2/100; //integer divided by integer
NSLog(@"%i divied by 100 prouces %f",i2,f1);
f2= i2/100.0; //integer divided by a float
NSLog(@"%i divied by 100.0 produces %f",i2,f2);
f2= (float)i2 /100; // type cast operator
NSLog(@"(float))%i divided by 100 produces %f",i2,f2);
有啥从NSLogs输出?? – samfisher 2012-07-20 07:13:12