byte byteValue()
描述 (Description)
java.lang.Number.byteValue()方法以字节形式返回指定数字的值。 这可能涉及舍入或截断。
声明 (Declaration)
以下是java.lang.Number.byteValue()方法的声明
public byte byteValue()
参数 (Parameters)
NA
返回值 (Return Value)
转换为byte类型后,此方法返回此对象表示的数值。
异常 (Exception)
NA
例子 (Example)
以下示例显示了lang.Number.byteValue()方法的用法。
package com.iowiki;
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());
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
x as integer:123456, x as byte:64
y as float:9876.0, y as byte:-108