目录

abstract long longValue()

描述 (Description)

java.lang.Number.longValue()方法以long形式返回指定数字的值。 这可能涉及舍入或截断。

声明 (Declaration)

以下是java.lang.Number.longValue()方法的声明

public abstract long longValue()

参数 (Parameters)

NA

返回值 (Return Value)

此方法在转换为long类型后返回此对象表示的数值。

异常 (Exception)

NA

例子 (Example)

以下示例显示了lang.Number.longValue()方法的用法。

package com.iowiki;
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
↑回到顶部↑
WIKI教程 @2018