• 📚 A new project from the admin: Check out PictureBooks.io, an AI storyteller that lets you build custom picture books for kids in seconds. Let me know what you think here!

never mind

Joined
Jun 27, 2007
Messages
2,248
Location
Hamilton, Ontario
If you assign a float to an int via casting

Code:
int iValue = (int) fValue;

the entire fraction is dropped. If you want a true rounding you need to use a function or do your own:

Code:
int iValue = (int) (fValue + 0.5);  // round to nearest int
 
Back
Top Bottom