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

ceil()

Example

Rounding numbers to the nearest whole number, always upwards.

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

Definition and Usage

The ceil() method rounds a number upwards to the nearest integer.

Hint: For rounding a number downwards to the nearest integer, refer to the floor() method.

Hint: For rounding a number to the nearest integer in either direction, consider using the round() method.

Syntax

public static double ceil(double number)

Parameter Values

Parameter

Description

number

Necessary: a number to be rounded upwards.

Technical Details

Returns

A double value indicating the nearest integer that is greater than or equal to the given number.

Java Version

Any