Skip to main content
Logo image

Section 6.3 Converting Floats to Integers

Casting a float to an integer sets the data type for that stored float as an int now, which means that instead of using mantissa and exponent to store the number, the binary 2’s complement is used. What happens if the original float had decimal places after the decimal point? Will they get lost? Will rounding occur? Try it out:

admin.....open in new window

Activity 6.2.

    When you cast a float to an int, which of the following happens?
  • Decimals are simply cut off.
  • Correct!
  • The float is rounded down.
  • Not quite - try again!
  • The float is rounded up.
  • Not quite - try again!
  • I can’t tell.
  • Not quite - try again!
Hint.
Just use the code window above to play around. Don’t be afraid! You can’t break anything!