Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"f" after number

What does the f after the numbers indicate? Is this from C or Objective-C? Is there any difference in not adding this to a constant number?

CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, 50.0f); 

Can you explain why I wouldn't just write:

CGRect frame = CGRectMake(0, 0, 320, 50); 
like image 947
typeoneerror Avatar asked Mar 06 '10 08:03

typeoneerror


People also ask

Why do we use F after every float value?

When representing a float data type in Java, we should append the letter f to the end of the data type; otherwise it will save as double. The default value of a float in Java is 0.0f. Float data type is used when you want to save memory and when calculations don't require more than 6 or 7 digits of precision.

Is %f for float in C?

The f suffix simply tells the compiler which is a float and which is a double .

What is %f in C programming?

'%f': Print a floating-point number in normal (fixed-point) notation. See Floating-Point Conversions, for details.

Is 5F a float in Java?

5 is of type integer where as 5f is of type float. Positions tend to use floats and doubles, since you need precision.


1 Answers

CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, 50.0f); 

uses float constants. (The constant 0.0 usually declares a double in Objective-C; putting an f on the end - 0.0f - declares the constant as a (32-bit) float.)

CGRect frame = CGRectMake(0, 0, 320, 50); 

uses ints which will be automatically converted to floats.

In this case, there's no (practical) difference between the two.

like image 69
Frank Shearar Avatar answered Sep 25 '22 04:09

Frank Shearar