开发者

float format variable with integer value in string

I was facing with one minor issue, and I'm wondering: Why?

here we have some string:

[NSString stringWithFormat@"%.3f/%.3f/%.3f/%i", 1.0, 1.0, 1, 1];

in this case, result is 1.000/1.000/1/abra-kadabra like 34875689. Why it's happens? Of course, I know, when we change the third value to 1.0, then everything will be okay. 开发者_开发百科So, please, explain me the deep proces of this operation.


Since you wrote %f, the compiler expects a float but recognizes an int. Writing 1 instead of 1.0 tells the compiler it's an integer constant instead of 1.0, which is a float constant.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜