Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

round()

Example

Rewrite: “Approximate the numbers to the nearest whole number.”

System.out.println(Math.round(0.60));
System.out.println(Math.round(0.40));
System.out.println(Math.round(5));
System.out.println(Math.round(5.1));
System.out.println(Math.round(-5.1));
System.out.println(Math.round(-5.9));

Definition and Usage

The round() function rounds a number to the closest integer.

Syntax

One of the following:

public static long round(double number)

 

public static int round(float number) 

Parameter Values

Parameter

Description

number

“Necessary. A value to be rounded.”

Technical Details

Returns:

“A long integer (if the argument is a double) or an integer (if the argument is a float) representing the closest whole number to a given value.”

Java Version:

Any