Java.lang Package Classes

Java Float - byteValue() Method



The java.lang.Float.byteValue() method returns the value of this Float as a byte after a narrowing primitive conversion.

Syntax

public byte byteValue()

Parameters

No parameter is required.

Return Value

Returns the float value represented by this object converted to type byte.

Exception

NA.

Example:

In the example below, the java.lang.Float.byteValue() method returns a Float object after conversion to type byte.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating Float objects
    Float val1 = 25.6f;
    Float val2 = -25.6f;

    //printing byteValue of the Float objects
    System.out.println("byteValue of the val1 is: " + val1.byteValue()); 
    System.out.println("byteValue of the val2 is: " + val2.byteValue());   
  }
}

The output of the above code will be:

byteValue of the val1 is: 25
byteValue of the val2 is: -25

❮ Java.lang - Float