strictmath
StrictMath类ceil()方法 (StrictMath Class ceil() method)
ceil() method is available in java.lang package.
ceil()方法在java.lang包中可用。
ceil() method is used to return the least or smallest value of the double type value which is greater than or equal to the given parameter.
ceil()方法用于返回大于或等于给定参数的double类型值的最小值或最小值。
ceil() method is a static method so this method is accessible with the class name too.
ceil()方法是静态方法,因此也可以使用类名访问此方法。
ceil() method does not throw any exception at the time of ceiling the given parameter.
在给定参数设置上限时, ceil()方法不会引发任何异常。
Syntax:
句法:
public static double ceil(double d);
Parameter(s):
参数:
double d – represents the double type value whose least value to be found.
double d –表示要找到其最小值的double类型值。
Return value:
返回值:
The return type of this method is double – it returns least value of the given parameter.
该方法的返回类型为double-返回给定参数的最小值。
Note:
注意:
If we pass NaN as an argument, method returns the same value (NaN).
如果我们将NaN作为参数传递,则方法将返回相同的值(NaN)。
If we pass zero (0), method returns the same value with the same sign.
如果传递零(0),则方法将返回具有相同符号的相同值。
If we pass an infinity, method returns the same value with the same sign.
如果我们传递一个无穷大,则方法将返回带有相同符号的相同值。
If we pass an argument which is less than 0, but greater than -1.0, method returns -0.0.
如果我们传递的参数小于0但大于-1.0,则方法返回-0.0。
If we pass an argument whose value after the decimal point is greater than 0, method returns the value incremented by 1.
如果我们传递的参数的小数点后的值大于0,则方法返回的值将增加1。
Example:
例:
// Java program to demonstrate the example
// of ceil(double d) method of StrictMath Class.
public class Ceil {
public static void main(String[] args) {
// Variable Declaration
double d1 = -0.0;
double d2 = 0.0;
double d3 = -7.0 / 0.0;
double d4 = 7.0 / 0.0;
double d5 = -0.6;
double d6 = 1000.0;
double d7 = 1000.4;
// Display previous value of d1,d2,d3,d4,d5 ,d6 and d7
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);
System.out.println("d7: " + d7);
// Here , we will get (-0.0) because we are passing
// parameter (-0.6) because passed value is less than 0
// but greater than -1.0
System.out.println("StrictMath.ceil(d1): " + StrictMath.ceil(d1));
// Here , we will get (0.0) because we are passing parameter (0.0)
System.out.println("StrictMath.ceil(d2): " + StrictMath.ceil(d2));
// Here , we will get (-Infinity) because we are passing parameter (-7.0/0.0)
System.out.println("StrictMath.ceil(d3): " + StrictMath.ceil(d3));
// Here , we will get (Infinity) because we are passing parameter (7.0/0.0)
System.out.println("StrictMath.ceil(d4): " + StrictMath.ceil(d4));
// Here , we will get (-0.0) because we are passing
// parameter (-0.6) because passed value is less than 0
// but greater than -1.0
System.out.println("StrictMath.ceil(d5): " + StrictMath.ceil(d5));
// Here , we will get (1000.0) because we are passing
// parameter (1000.0) because passed value after decimal
// point is not greater than 0 so the same number is //returned
System.out.println("StrictMath.ceil(d6): " + StrictMath.ceil(d6));
// Here , we will get (1001.0) because we are passing
// parameter (1000.4) because passed value after decimal
// point is greater than 0 so the number is incremented by 1 is returned
System.out.println("StrictMath.ceil(d7): " + StrictMath.ceil(d7));
}
}
Output
输出量
d1: -0.0
d2: 0.0
d3: -Infinity
d4: Infinity
d5: -0.6
d6: 1000.0
d7: 1000.4
StrictMath.ceil(d1): -0.0
StrictMath.ceil(d2): 0.0
StrictMath.ceil(d3): -Infinity
StrictMath.ceil(d4): Infinity
StrictMath.ceil(d5): -0.0
StrictMath.ceil(d6): 1000.0
StrictMath.ceil(d7): 1001.0
翻译自: https://www.includehelp.com/java/strictmath-ceil-method-with-example.aspx
strictmath