email me at borlaj@portlandschools.org

Loading
notes previous (10/<10) submit the dump links  
 

Casting:

 

If we had a decimal say 4.5 and tried to save it as an int ie:

int x=4.5;

 

We would get an error (possible loss of precision). But say we really want an int, we can say, yes, thats what we want by casting it. This just tells the computer we are okay losing the decimal portion. To do that we say:

 

int x = (int) 4.5;

This makes x equal 4.