I've observed the following surprising result
System.out.println((int) (5.1f * 10f)); => 51
System.out.println((int) (5.1f * 10d)); => 50
This is because Java does an implicit cast on the float during the multiplication, i.e. Java is actually doing this...
System.out.println((double)5.1f * 10d); => 50
and casting 5.1f to double gives the result
System.out.println((double) 5.1f); => 5.099999904632568
I'm struggling to understand why casting to a more precise type gives a less precise result. I'd only expect a loss of precision if going from double to float, not from float to double...
Double to float gives a less surprising result...
System.out.println((float) 5.1d); // => 5.1