I have this code:
float number1 = 2f / 12;
System.out.println(number1);
int number2 = 6;
float x = number1 * number2;
System.out.println(x);
And as output I get:
0.16666667
1.0
Why? When I multiply number1 and number2, number2 should be promoted to float type, and I should get a 0.96
When I modify my code to:
float number1 = 0.16f;
System.out.println(number1);
int number2 = 6;
float x = number1 * number2;
System.out.println(x);
I get good result:
0.16
0.96
Why operation float = float * int
in first example produces the bad result?