Most of the time, Java developers have to do type conversion. In this example, I will cover the conversion of float datatype to int . There are several ways to achieve this. Solution 1 public class FloatToIntCasting { public static void main( String[] args ) { float value = 0.9f; System.out.println( "0.9f converted to int : " + (int) value ); value = 1.1f; System.out.println( "1.1f converted to int : " + (int) value ); } } Output 0.9 f converted to int : 0 1.1 f converted to int : 1 As we can see in the above example, casting a float to int results in downcasting. It simply removes the fraction part and returns the value. Solution 2 public class FloatToIntUsingMathRound { public static void main( String[] args ) { float value = 0.9f; System.out.println( "0.9f rounded to int : " +
Blog about programming