The Type int

Explicit Conversion

A simple way to avoid the automatic type conversion is to request a conversion explicitly. That can be accomplished in the following manner:

int y = int(6.73);

This piece of code will generate no warnings, as a type conversion is explicitly requested. No automatic type conversion is required here, but a type conversion will take place. This kind of type conversion is called type casting and in this case, the value 6.73 is being cast to type int. The result is the value 6 of type int.

Of course, this is just an example. To get the same effect we could have simply written:

int y = 6;