Java.lang.Double.byteValue() Method

Advertisements


Description

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

Declaration

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

public byte byteValue()

Parameters

  • NA

Return Value

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

Exception

  • NA

Example

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

package com.tutorialspoint;

import java.lang.*;

public class DoubleDemo {

   public static void main(String[] args) {

     /* returns the double value represented by this object converted 
     to type byte */
     Double obj = new Double("20");
     byte b = obj.byteValue();
     System.out.println("Value = " + b);
    
     obj = new Double("30.95");
     b = obj.byteValue();
     System.out.println("Value = " + b);
  }
} 

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

Value = 20
Value = 30



Advertisements
Advertisements