Round to int to double

ReturnMethodSummary
static doublerint(double a)Returns the double value that is closest to a and is equal to an integer.

public class Main {
  public static void main(String[] args) {

    System.out.println(Math.rint(1.2));
    System.out.println(Math.rint(1.9));
  }
}

The output:


1.0
2.0
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.