java.lang.Number.longValue() 方法返回指定數位作為long的值。這可能會涉及到舍入或截斷。
以下是java.lang.Number.longValue()方法的宣告
public abstract long longValue()
NA
此方法返回該物件表示轉換為long型別後的數值。
NA
下面的例子顯示lang.Number.longValue()方法的使用。
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 long System.out.println("x as float:" + x + ", x as long:" + x.longValue()); System.out.println("y as double:" + y + ", y as long:" + y.longValue()); } }
讓我們來編譯和執行上面的程式,這將產生以下結果:
x as float:123456.0, x as long:123456 y as double:9876.0, y as long:9876