The java.lang.Number.byteValue() method returns the value of the specified number as a byte. This may involve rounding or truncation.
Following is the declaration for java.lang.Number.byteValue() method
public byte byteValue()
NA
This method returns the numeric value represented by this object after conversion to type byte.
NA
The following example shows the usage of lang.Number.byteValue() method.
package com.tutorialspoint; public class NumberDemo { public static void main(String[] args) { // get a number as integer Integer x = new Integer(123456); // get a number as float Float y = new Float(9876f); // print their value as byte System.out.println("x as integer:" + x + ", x as byte:" + x.byteValue()); System.out.println("y as float:" + y + ", y as byte:" + y.byteValue()); } }
Let us compile and run the above program, this will produce the following result −
x as integer:123456, x as byte:64 y as float:9876.0, y as byte:-108