Dart ceil() Method

Last updated on March 12, 2023 by Ayaz Ali Shah

The ceil() method returns the nearest and smallest integer greater than or equal to the number. This means if you apply the ceil() method on a double value of 3.05, it would return 4 with an integer because 4 is the nearest number to 3.05, and also the smallest number. Further, it is greater than too if you compare it with 3.05.

Syntax

number.ceil()

Parameters

The ceil() method does not take any parameter, it attaches with the value or variable through dot notation.

Example

Let’s create a variable and store a double value for it.

var doubleValue = 5.05;

Next, access the ceil() method through dot notation which will convert the value into an integer.

var convertedValue = doubleValue.ceil();
print(convertedValue);
// Output: 6

Here the ceil() method returns 6 with the integer data type. Because 6 is the nearest value of 5.05 and also greater than 5.05.

If you want to check the data type of the converted value then use the runtimeType property.

print(convertedValue.runtimeType);
// Output: int

We applied the ceil() method on different values, below are a few examples.

Example 01

var doubleValue = 10.00;
var convertedValue = doubleValue.ceil();
print(convertedValue);
// Output: 10

Example 02

var doubleValue = 10.01;
var convertedValue = doubleValue.ceil();
print(convertedValue);
// Output: 11


Share on:

Related Posts