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);
More Related Contents:
- How do I add an "L" to the end of an integer?
- How can I properly compare two Integers in Java?
- Large Numbers in Java
- Integer wrapper objects share the same instances only within the value 127? [duplicate]
- Why doesn’t Java support unsigned ints?
- What does value & 0xff do in Java?
- Different between parseInt() and valueOf() in java?
- Declaring an unsigned int in Java
- Using == operator in Java to compare wrapper objects
- Why equal operator works for Integer value until 128 number? [duplicate]
- Converting List to List
- How to do an Integer.parseInt() for a decimal number?
- Javascript long integer
- How can I pass an Integer class correctly by reference?
- Parsing a Hexadecimal String to an Integer throws a NumberFormatException?
- How to cast an Object to an int
- How to implement infinity in Java?
- Integer vs int: with regard to memory
- Multiplication of two ints overflowing to result in a negative number
- Check if int is between two numbers
- Arrays.asList() of an array
- How can I detect integer overflow on 32 bits int?
- Integer.toString(int i) vs String.valueOf(int i) in Java
- Differences between new Integer(123), Integer.valueOf(123) and just 123
- Integer.parseInt(scanner.nextLine()) vs scanner.nextInt()
- Java JDK – possible lossy conversion from double to int
- Why does Java think that the product of all numbers from 10 to 99 is 0?
- Why are Integers immutable in Java?
- Is 00 an integer or octal in Java?
- Using int vs Integer