Java Math nextDown() 方法
示例
查找不同数字下方最近的浮点数
System.out.println(Math.nextDown(1.0f));
System.out.println(Math.nextDown(1.0));
System.out.println(Math.nextDown(0.5f));
System.out.println(Math.nextDown(0.5));
System.out.println(Math.nextDown(Math.PI));
System.out.println(Math.nextDown(3.1415927f));
定义和用法
nextDown()
方法返回一个浮点数,该浮点数在负方向上与一个数字相邻,是小于起始数字的最高可能浮点数。
对于 double
类型的参数,返回值将比 float
类型的参数更接近起始数字。
语法
以下之一
public static double nextDown(double start)
public static float nextDown(float start)
参数值
参数 | 描述 |
---|---|
start | 必需。起始数字。 |
技术详情
返回 | 一个 double 或 float 值,表示在负方向上与起始数字相邻的浮点数。 |
---|---|
Java 版本 | 1.8+ |
❮ Math 方法