109
Java Float byteValue() method
The byteValue() of Java Float class returns the value of this Float as a byte by narrowing the primitive values or in simple words by casting to a byte.
Syntax:
Parameters:
NA
Return Value:
This method returns the bytevalue which has been converted from the float value of this object.
Example 1
Output:
Sum = 60.44 Sum = 60
Example 2
Output:
float value = 10.5 Converted byte value by type casting = 10 Converted byte value by byteValue method=10
Example 3
Output:
Error:(16, 72) java: float cannot be dereferenced -
Float is a primitive data type; its object cannot be used to call the Float class method. If you do this, you will get an error like above example.
Next TopicJava Float