Do I need to use decimal places when using floats? Is the "f" suffix necessary?
Posted
by Paulo Fierro
on Stack Overflow
See other posts from Stack Overflow
or by Paulo Fierro
Published on 2010-03-08T15:48:32Z
Indexed on
2010/03/08
15:51 UTC
Read the original article
Hit count: 358
iphone
|objective-c
I've seen several examples in books and around the web where they sometimes use decimal places when declaring float values even if they are whole numbers, and sometimes using an "f" suffix. Is this necessary?
For example:
[UIColor colorWithRed:0.8 green:0.914 blue:0.9 alpha:1.00];
How is this different from:
[UIColor colorWithRed:0.8f green:0.914f blue:0.9f alpha:1.00f];
Does the trailing "f" mean anything special?
Getting rid of the trailing zeros for the alpha value works too, so it becomes:
[UIColor colorWithRed:0.8 green:0.914 blue:0.9 alpha:1];
So are the decimal zeros just there to remind myself and others that the value is a float?
Just one of those things that has puzzled me so any clarification is welcome :)
© Stack Overflow or respective owner