Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Jack Raiden
7,976 Pointswhy the duration is "5.0f" not "5.0s"?
I notice that instructor put that 'f' right after 5.0, but I am confused why "f" stands for seconds here, shouldn't "s" be more intuitive?
1 Answer
Kristen Law
16,244 Pointsf isn't used as a unit, but rather it denotes that the number is a float constant. If it was just 5.0 instead of 5.0f, it would be a double constant.
From Stack Overflow:
Without a suffix, a literal with a decimal in it (123.0) will be treated as a double-precision floating-point number. If you assign or pass that to a single-precision variable or parameter, the compiler will (should) issue a warning. Appending "f" tells the compiler you want the literal to be treated as a single-precision floating-point number.