Java | round()
La méthode round() est une méthode mathématique intégrée qui renvoie une valeur de type int ou long la plus proche de l’argument.
Syntaxe
Cette méthode a les syntaxes suivantes:
int round(float f) long round(double d)
Paramètres
- d | f : Une valeur de type double ou float.
Valeur de retour
La méthode renvoie une valeur de type int ou long, la plus proche de l’argument.
Exemple :
Le code suivant montre comment utiliser la méthode round():
public class Main {
public static void main(String args[]) {
double d = 2.89;
float f = 50;
System.out.println(Math.round(d));
System.out.println(Math.round(f));
}
}
public class Main {
public static void main(String args[]) {
double d = 2.89;
float f = 50;
System.out.println(Math.round(d));
System.out.println(Math.round(f));
}
}
public class Main { public static void main(String args[]) { double d = 2.89; float f = 50; System.out.println(Math.round(d)); System.out.println(Math.round(f)); } }
Sortie:
3 50