Java StrictMath.round(float a)

Syntax

StrictMath.round(float a) has the following syntax.

public static int round(float a)

Example

In the following code shows how to use StrictMath.round(float a) method.


/* ww  w  .j  a  va  2 s  .c  o m*/

public class Main {

  public static void main(String[] args) {
  
   float f1 = 12.34f , f2 = 56.78f;
    
   System.out.println("closest int value to " + f1 + " = " + StrictMath.round(f1));
    
   System.out.println("closest int value to " + f2 + " = " + StrictMath.round(f2));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable