You can’t assign a float
value to an int
variable because some of the information will be lost. For the same reason, you can’t pass a float
value to a method whose argument is declared as an int
. (your question is rather unclear due to the incorrect use of terminology, but I think you are trying to do the latter)
You can tell the compiler that you really do want to lose the information (the fractional part of the float) by using a cast operation. That is the how, and the why.
solved Why can’t I pass a int to a float in the same statement? [closed]