if 123/33 prints out 3 and 3 is an integer if we cast it to float ( (float)123/33 )how do we get the decimal places from the integer 3. does 3 contains floating points internally what ?
public static void test() {
System.out.println("==========");
System.out.println(123/33); // prints 3
System.out.println((float)123/33); // prints 3.7272727
//so if we cast it to float we get the decimal points also (.7272727)
}
The cast does not apply to the entire expression
123/33
. You're casting the value123
to a float, which causes any further operations to use floating-point math.