How do I convert float to integer? [duplicate]

There are two options:

  • casting: this will produce an unrounded result. For example: 2.7 will be converted to 2.

    int someInt = (int) someFloat;

  • rounding: the result will be rounded correctly.

    int someInt = Math.round(someFloat);

Leave a Comment