public static double floor(double a)
Returns the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer. Special cases: 
?If the argument value is already equal to a mathematical integer, then the result is the same as the argument. 
?If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
Parameters:aReturns:the largest (closest to positive infinity) floating-point value that is not greater than the argument and is equal to a mathematical integer.

解决方案 »

  1.   

    ceilpublic static double ceil(double a)
    Returns the smallest (closest to negative infinity) double value that is not less than the argument and is equal to a mathematical integer. Special cases: 
    ?If the argument value is already equal to a mathematical integer, then the result is the same as the argument. 
    ?If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument. 
    ?If the argument value is less than zero but greater than -1.0, then the result is negative zero.
    Note that the value of Math.ceil(x) is exactly the value of -Math.floor(-x).Parameters:aReturns:the smallest (closest to negative infinity) floating-point value that is not less than the argument and is equal to a mathematical integer.
      

  2.   

    roundpublic static int round(float a)
    Returns the closest int to the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type int. In other words, the result is equal to the value of the expression: (int)Math.floor(a + 0.5f)Special cases: 
    ?If the argument is NaN, the result is 0. 
    ?If the argument is negative infinity or any value less than or equal to the value of Integer.MIN_VALUE, the result is equal to the value of Integer.MIN_VALUE. 
    ?If the argument is positive infinity or any value greater than or equal to the value of Integer.MAX_VALUE, the result is equal to the value of Integer.MAX_VALUE.
    Parameters:a - a floating-point value to be rounded to an integer.Returns:the value of the argument rounded to the nearest int value.See Also:Integer.MAX_VALUE, Integer.MIN_VALUE
    roundpublic static long round(double a)
    Returns the closest long to the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type long. In other words, the result is equal to the value of the expression: (long)Math.floor(a + 0.5d)Special cases: 
    ?If the argument is NaN, the result is 0. 
    ?If the argument is negative infinity or any value less than or equal to the value of Long.MIN_VALUE, the result is equal to the value of Long.MIN_VALUE. 
    ?If the argument is positive infinity or any value greater than or equal to the value of Long.MAX_VALUE, the result is equal to the value of Long.MAX_VALUE.
    Parameters:a - a floating-point value to be rounded to a long.Returns:the value of the argument rounded to the nearest long value.See Also:Long.MAX_VALUE, Long.MIN_VALUE
      

  3.   

    floor(a) 返回不大于a的最大整数,返回类型double
    round(a) 返回离a最接近的整数,返回类型int
    ceil(a) 返回大于a的最小整数,返回类型double
    如:
    System.out.println(Math.floor(2.36));      //2.0
    System.out.println(Math.round(2.56));      //3
    System.out.println(Math.round(-2.36));     //-2
    System.out.println(Math.ceil(2.56));       //3.0
      

  4.   

    System.out.println(Math.floor(-2.36));      //-3.0
    System.out.println(Math.round(-2.56));      //-3
    System.out.println(Math.round(2.36));       //2
    System.out.println(Math.ceil(-2.56));       //-2.0