previous |
start |
next
Type Conversion
- In assignment, types must match.
double total = "a lot"; // no
- Use “cast” (int) to convert floating-point
values to integer values:
int pennies
= (int)(total * 100);
Cast discards fractional part.
- Use Math.round for rounding:
int dollar =
(int)Math.round(total);
previous |
start |
next