println
public void println(float x)
Prints a float and then terminate the line. This method behaves as though it invokes print(float) and then println().
Parameters:
x - The float to be printed.
public void print(float f)
Prints a floating-point number. The string produced by String.valueOf(float) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.
Parameters:
f - The float to be printed
See Also:
Float.toString(float)
Charles O'Leary wrote:
However, my expectations were 4.0f + 1.0f ->5.0f? Why are the results 5.0 (especially since this is not a float)? How is printing 5.0f achieved?
Henry Wong wrote:
Printing a "float" in this case, means printing a floating point number. The syntax used is either the scientific notation (with a decimal point and an E for the "times ten to"), or the standard floating point (with just the decimal point). Neither syntax has an "f". If you want the "f", you can print it out yourself.
Henry
println
public void println(float x)
Prints a float and then terminate the line. This method behaves as though it invokes print(float) and then println().
Parameters:
x - The float to be printed.
public void print(float f)
Prints a floating-point number. The string produced by String.valueOf(float) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.
Parameters:
f - The float to be printed
See Also:
Float.toString(float)
enthuware.ocajp.i.v8.2.1277: Note that System.out.println((float)5/4); will print 1.25. If you remove the explicit cast (float), it will print 1.
Charles O'Leary wrote:
Although I had anticipated that as a possible reply, isn't this highlighting a possible API errata (since there appears to be a clear contradiction)?
Henry Wong wrote:
Charles O'Leary wrote:
Although I had anticipated that as a possible reply, isn't this highlighting a possible API errata (since there appears to be a clear contradiction)?
Can you elaborate? What contradiction are you referring to here? It is certainly not very clear, if at all.
Henry
Henry Wong wrote:Floating point numbers, when printed, are *not* 32 bit or 64 bit. They are simply output -- that adheres to a particular format.
And there is no information in that format that indicates that the original number, that was used for the print out, was 32 bit or 64 bit. In other words, printing a 32 bit float type, and having it without the "f", does not mean it got cast to a double.
Henry
literals are assumed to be double, unless postfixed with an f, as in 2.1f
Don't get me started about those stupid light bulbs. |