Java Math floor示例

时间:2020-02-23 14:35:05  来源:igfitidea点击:

Java Math Floor函数用于获得比数字更小的整数。

语法

public static double floor(double x)

例子

让我们在该示例中使用数学的floor函数。

package org.igi.theitroad;
 
public class MathFloorMain {
 
	public static void main(String[] args) {
 
		//Use math.floor to get largest integer lesser
		//than number
		System.out.println("floor value for 2.6 = " + Math.floor(2.6));
		System.out.println("floor value for 26.1 = " + Math.floor(26.1));
		System.out.println("floor value for -0.8 = " + Math.floor(-0.8));
		System.out.println("floor value for -6.2 = " + Math.floor(-6.2));
 
		float f=4.6f;
		System.out.println("floor value for 4.6f = " + Math.floor(f));	
 
	}
}

运行上述程序时,程序的输出将是:

Ceil value for 2.6 = 3.0
Ceil value for 26.1 = 27.0
Ceil value for -0.8 = -0.0
Ceil value for -6.2 = -6.0
Ceil value for 4.6f = 5.0