java tutorial - Java Math.rint() Method - tutorial java - java programming - learn java - java basics - java for beginners



Java numbers rint

Learn Java - Java tutorial - Java numbers rint - Java examples - Java programs

Description

Method Math.rint () Returns an integer that is nearest to the value of the argument, in other words - rounds the fraction to the whole.

Syntax

double rint(double d)
click below button to copy the code. By - java tutorial - team

Options

Detailed information about the parameters:

  • d - takes the value of double as a parameter.

Return value

  • In Java, Math.rint () returns an integer that is closest in the argument value. Returns as a double.

Sample Code

public class Test { 

   public static void main(String args[]) {
      double a = 10.200;
      double b = 10.500;
      double c = 10.501;
      double d = 10.675;
      
      System.out.println("a = " + Math.rint(a));
      System.out.println("b = " + Math.rint(b));
      System.out.println("c = " + Math.rint(c)); 
      System.out.println("d = " + Math.rint(d)); 
   }
}
click below button to copy the code. By - java tutorial - team

Output

a = 10.0
b = 10.0
c = 11.0
d = 11.0

Related Searches to Java Math.rint() Method