java.lang.Number.shortValue() 方法返回指定數的short值。這可能會涉及到舍入或截斷。
以下是java.lang.Number.shortValue()方法的宣告
public abstract short shortValue()
NA
此方法返回該物件表示轉換為short型別後的數值。
NA
下面的例子顯示lang.Number.shortValue()方法的使用。
package com.yiibai; public class NumberDemo { public static void main(String[] args) { // get a number as float Float x = new Float(123456f); // get a number as double Double y = new Double(9876); // print their value as short System.out.println("x as float :" + x + ", x as short:" + x.shortValue()); System.out.println("y as double:" + y + ", y as short:" + y.shortValue()); } }
讓我們來編譯和執行上面的程式,這將產生以下結果:
x as float :123456.0, x as short:-7616 y as double:9876.0, y as short:9876