Sometimes I write a float like:
0.1
and sometimes I add an f, like:
0.1f
It often seems that both ways work. I picked the f up from some sample code. But what's that actually good for? I'm sure it means "float", but do I really need that?
Sometimes I write a float like:
0.1
and sometimes I add an f, like:
0.1f
It often seems that both ways work. I picked the f up from some sample code. But what's that actually good for? I'm sure it means "float", but do I really need that?
I believe it is indicating that the number is a float
(i.e. single-precision floating point) as opposed to a double
(double-precision floating point), which is the default, i.e. no prefix. You might be able to use either interchangeably because the compiler can do implicit conversion, but by appending the suffix you're being explicit, and quite possibly has some performance benefits in avoiding the conversion too.
I don't have any direct knowledge of Obective-C, but this is the case for several other C-style languages (e.g. C#, Java, and C itself), and I would imagine it would be exactly the same here.