Referring to why f is placed after float values? now consider this,
float f = 56.7876f;
System.out.print(String.format("%32.12f", f)); // 56.787601470947
System.out.print(String.format("%32.12f", 56.7876)); // 56.787600000000
System.out.print(String.format("%32.12f", 56.7876f)); // 56.787601470947
For floating point literals the default type is double
. When you say, f = 56.7876
, the compiler will give warning Type mismatch: cannot convert from double to float
. You would need to explicitly type cast it to float (considering the loss of precision from double to float).
In this example the output printed from 56.7876 is of type double 56.787600000000 while the rest are of type float.
To give you a better example, conider the following scenario.
float f = 56.7874f;
System.out.print(String.format("%32.12f", f)); // 56.787399291992
System.out.print(String.format("%32.12f", 56.7874)); // 56.787400000000
System.out.print(String.format("%32.12f", 56.7874f)); // 56.787399291992
This clearly indicates a loss of precision from 56.7874
to 56.7873