how can one get an integer output from float inputs in java | SoloLearn: Learn to code for FREE!

+2

how can one get an integer output from float inputs in java

6/3/2020 12:47:05 AM

Dickie Mwiry

4 Answers

New Answer

+2

By casting or conversion - Integer.valueOf() e.g.

+1

thanks let me try

0

narrowing casting

-1

James Clark I. Vinarao The Integer.valueOf() method does not convert floats to ints. See... https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/lang/Integer.html Just downcast it as LAKSHMI NARAYANAN M mentioned. float f = 1.2345f; int i; i = (int)f;