Java.lang.Float.byteValue() Method


Advertisements


Description

The java.lang.Float.byteValue() method returns the value of this Float as a byte (by casting to a byte).

Declaration

Following is the declaration for java.lang.Float.byteValue() method

public byte byteValue()

Parameters

NA

Return Value

This method returns the float value represented by this object converted to type byte.

Exception

NA

Example

The following example shows the usage of java.lang.Float.byteValue() method.

package com.tutorialspoint;

import java.lang.*;

public class FloatDemo {

   public static void main(String[] args) {

      /* returns the float value represented by this object converted 
         to type byte */
      Float obj = new Float("10");
      byte b = obj.byteValue();
      System.out.println("Value = " + b);
    
      obj = new Float("15.45");
      b = obj.byteValue();
      System.out.println("Value = " + b);
   }
}  

Let us compile and run the above program, this will produce the following result −

Value = 10
Value = 15

java_lang_float.htm

Advertisements