Java 如何将浮动部分调整为下一个整数值

Java 如何将浮动部分调整为下一个整数值,java,android,Java,Android,对于我的应用程序,我需要将浮点数转换并调整为最接近的整数 public class MathDemo { public static void main(String[] args) { // get two double numbers double x = 60984.1; double y = -497.99; double x1 = 125.9; double y1 = 0.4873; // call ceal for the

对于我的应用程序,我需要将浮点数转换并调整为最接近的整数

public class MathDemo {

   public static void main(String[] args) {

      // get two double numbers
      double x = 60984.1;
      double y = -497.99;
   double x1 = 125.9;
  double y1 = 0.4873;

  // call ceal for these these numbers
  System.out.println("Math.ceil(" + x1 + ")=" + Math.ceil(x1));
  System.out.println("Math.ceil(" + y1 + ")=" + Math.ceil(y1));
  System.out.println("Math.ceil(-0.65)=" + Math.ceil(-0.65));


      // call floor and print the result
      System.out.println("Math.floor(" + x + ")=" + Math.floor(x));
      System.out.println("Math.floor(" + y + ")=" + Math.floor(y));
      System.out.println("Math.floor(0)=" + Math.floor(0));
   }
}
比如说

5.430至5

5.767至6

4.32至4

如何在android中存档此文件


我已经使用了math.ceil()和math.nextup()函数,。但是它不起作用。

使用will将浮点舍入到最接近的整数。

您尝试了什么?请参阅@Frédéric的可能副本,我的问题不是您提到的链接的副本。如果浮点部分大于.5,我的要求是将浮点部分四舍五入为整数,但如果我们使用math.ceil(),则浮点部分将更改为下一个整数,即使输入值为3.0001,也不正确
public class MathDemo {

   public static void main(String[] args) {

      // get two double numbers
      double x = 60984.1;
      double y = -497.99;
   double x1 = 125.9;
  double y1 = 0.4873;

  // call ceal for these these numbers
  System.out.println("Math.ceil(" + x1 + ")=" + Math.ceil(x1));
  System.out.println("Math.ceil(" + y1 + ")=" + Math.ceil(y1));
  System.out.println("Math.ceil(-0.65)=" + Math.ceil(-0.65));


      // call floor and print the result
      System.out.println("Math.floor(" + x + ")=" + Math.floor(x));
      System.out.println("Math.floor(" + y + ")=" + Math.floor(y));
      System.out.println("Math.floor(0)=" + Math.floor(0));
   }
}