Java.lang.Byte.floatValue() Method


Advertisements


Description

The java.lang.Byte.floatValue() returns the value of this Byte as a float.

Declaration

Following is the declaration for java.lang.Byte.floatValue() method

public float floatValue()

Specified by

floatValue in class Number

Parameters

NA

Return Value

This method returns the numeric value represented by this object after conversion to type float.

Exception

NA

Example

The following example shows the usage of lang.Byte.floatValue() method.

package com.tutorialspoint;

import java.lang.*;

public class ByteDemo {

   public static void main(String[] args) {

      // create 2 Byte objects b1, b2
      Byte b1, b2;

      // create 2 float primitives f1, f2
      float f1, f2;

      // assign values to b1, b2
      b1 = new Byte("100");
      b2 = new Byte("-10");

      // assign float values of b1, b2 to f1, f2
      f1 = b1.floatValue();
      f2 = b2.floatValue();

      String str1 = "float value of Byte " + b1 + " is " + f1;
      String str2 = "float value of Byte " + b2 + " is " + f2;

      // print f1, f2 values
      System.out.println( str1 );
      System.out.println( str2 );
   }
}

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

float value of Byte 100 is 100.0
float value of Byte -10 is -10.0

java_lang_byte.htm

Advertisements