Java Double.shortValue() 方法及代码示例
将当前 Double
进行原始值缩小转换后返回 short
.
初见版本
1.1定义
public short shortValue()
返回值
返回当前对象的 short
型表示
说明
由 Number
类的 shortValue()
方法指定实现.
具体实现参阅 Java™ 语言规范: 5.1.3 原始值缩小转换
示例
获取 Double 对象 short 型值的示例
package com.yi21.Double; public class Yi21DoubleShortValue { public static void main(String[] args) { Double d = 0.0; System.out.println(d + " 的 short 型值: " + d.shortValue()); d = -0.0; System.out.println(d + " 的 short 型值: " + d.shortValue()); d = -65535.0; System.out.println(d + " 的 short 型值: " + d.shortValue()); d = Double.NaN; System.out.println(d + " 的 short 型值: " + d.shortValue()); d = Double.POSITIVE_INFINITY; System.out.println(d + " 的 short 型值: " + d.shortValue()); d = Double.MAX_VALUE; System.out.println(d + " 的 short 型值: " + d.shortValue()); } }
执行结果为 :
0.0 的 short 型值: 0 -0.0 的 short 型值: 0 -65535.0 的 short 型值: 1 NaN 的 short 型值: 0 Infinity 的 short 型值: -1 1.7976931348623157E308 的 short 型值: -1