Skip to main content
Contents Index
Search Book
Search Results:
No results.
Readability settings Prev Up Next
\(\newcommand{\N}{\mathbb N}
\newcommand{\Z}{\mathbb Z}
\newcommand{\Q}{\mathbb Q}
\newcommand{\R}{\mathbb R}
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 6.4 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:
Compile and run the code below in your own C environment.
#include <stdio.h>
int main(void)
{
/* What happens when you cast a float to an int? */
return(0);
}
Activity 6.2 .
When you cast a
float to an
int, which of the following happens?
Hint .
Just use the code window above to play around. Don’t be afraid! You can’t break anything!