When creating float variables, integers don't need a type suffix, i.e. all of these are valid:
public float distance = 3;
public float distance = 3f;
public float distance = 0.3f;
Is there a reason to use 3f
instead of 3
? Is the compiler smart enough to recognize the type as float and automatically cast it?
Related Questions: Why Should we use literals in C# and Why is the "f" required when declaring floats
Both explain why we need to use the type suffix 'f', but is there a 'correct' way to declare floats that have integer values? Is one way more efficient?