strictmath
StrictMath类floor()方法 (StrictMath Class floor() method)
floor() method is available in java.lang package.
floor()方法在java.lang包中可用。
In this method, if the value of the given positive argument after decimal point is 0 or greater than 0 so in that case, it returns the same number before decimal point else if the value of the given negative argument after decimal point is greater than 0 so it returns (the same number +1) before decimal point.
在此方法中,如果给定的正参数的小数点后的值是0或大于0,那么在这种情况下,它将返回小数点前的相同数字,否则,如果给定的负参数的小数点后的值大于0因此它返回小数点前的(相同数字+1)。
floor() method is a static method so it is accessible with the class name and if we try to access the method with the class object then we will not get any error.
floor()方法是一个静态方法,因此可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会出现任何错误。
floor() method does not throw any exception.
floor()方法不会引发任何异常。
Syntax:
句法:
public static double floor(double d);
Parameter(s):
参数:
double d – represents the double type value whose floor value to be found.
double d –表示要找到其底值的double类型值。
Return value:
返回值:
The return type of this method is double – it returns the greatest floating-point value of the given argument and the argument value may be less than or equal to the given argument.
此方法的返回类型为double-返回给定参数的最大浮点值,并且参数值可以小于或等于给定参数。
Note:
注意:
If we pass NaN as an argument, method returns the same value (NaN).
如果我们将NaN作为参数传递,则方法将返回相同的值(NaN)。
If we pass an infinity (positive or negative), method returns the same value (i.e. positive or negative infinity).
如果我们传递无穷大(正或负),则方法将返回相同的值(即正无穷或负无穷)。
If we pass zero (0) positive or negative, method returns the same.
如果我们传递零(0)正或负,则方法将返回相同的值。
Example:
例:
// Java program to demonstrate the example of
// floor(double d) method of StrictMath Class.
public class Floor {
public static void main(String[] args) {
// variable declarations
double d1 = 7.0 / 0.0;
double d2 = -7.0 / 0.0;
double d3 = 0.0;
double d4 = -0.0;
double d5 = -123.1;
double d6 = 123.456;
// Display previous value of d1,d2,d3,d4,d5 and d6
System.out.println("d1: " + d1);
System.out.println("d2: " + d2);
System.out.println("d3: " + d3);
System.out.println("d4: " + d4);
System.out.println("d5: " + d5);
System.out.println("d6: " + d6);
// Here , we will get (Infinity) because we are
// passing parameter whose value is (infinity)
System.out.println("StrictMath.floor(d1): " + StrictMath.floor(d1));
// Here , we will get (-Infinity) because we are passing
// parameter whose value is (-infinity)
System.out.println("StrictMath.floor(d2): " + StrictMath.floor(d2));
// Here , we will get (0.0) because we are
// passing parameter whose value is (0.0)
System.out.println("StrictMath.floor(d3): " + StrictMath.floor(d3));
// Here , we will get (-0.0) because we are passing
// parameter whose value is (-0.0)
System.out.println("StrictMath.floor(d4): " + StrictMath.floor(d4));
// Here , we will get (-124.0) because we are
// passing parameter whose value is (-123.1)
System.out.println("StrictMath.floor(d5): " + StrictMath.floor(d5));
// Here , we will get (123.0) because we are
// passing parameter whose value is (123.456)
System.out.println("StrictMath.floor(d6): " + StrictMath.floor(d6));
}
}
Output
输出量
d1: Infinity
d2: -Infinity
d3: 0.0
d4: -0.0
d5: -123.1
d6: 123.456
StrictMath.floor(d1): Infinity
StrictMath.floor(d2): -Infinity
StrictMath.floor(d3): 0.0
StrictMath.floor(d4): -0.0
StrictMath.floor(d5): -124.0
StrictMath.floor(d6): 123.0
翻译自: https://www.includehelp.com/java/strictmath-floor-method-with-example.aspx
strictmath