Changing Variables to Floats

I understand the need to change some variable to floats by putting f after the number. Why in some cases is the syntax “6.0f” or “6.f” with our without the “zero” Or does it matter?

1 Like

In c++, it doesn’t matter whether you use 6.0f or 6.f. And no particularly reason why you’d use one over the other either.

1 Like

I’m still confused on why these numbers need to be a float versus just an integer. We’re changing it because by default it reads as a double? Is that it?

1 Like

While we could have stuck with a double (0.0), using a float (0.0f or 0.f) uses less memory because it stores less data (ie. is less precise) and we don’t need the extra precision.

If we tried to use an integer, however, we’d lose too much precision. As any value that has a decimal value is rounded down (0.4 becomes 0). This is important for frame rates for animations because the timings are almost always in values between 0 and 1, since they represent frames per second.

3 Likes

This makes sense, thank you so much!

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms