What is the ceil() function in Dart?

Overview

The ceil() function in Dart returns the nearest smallest integer value greater than or equal to a number.

The figure below shows the mathematical representation of the ceil() function.

Mathematical representation of ceil() function

Syntax


number.ceil()

Parameter

This function does not require a parameter.

Return value

ceil() returns the nearest, smallest integer value greater than or equal to a number.

Example

The code below shows the use of the ceil() function in Dart.

import 'dart:convert';
void main() {
//positive number
print("The value of (1.5).ceil(): ${(1.5).ceil()} ");
// negative number
print("The value of (-5.5).ceil(): ${(-5.5).ceil()} ");
//zero
print("The value of (0).ceil(): ${(0).ceil()}");
}

Explanation

  • Line 5: We calculate the ceiling value of the positive number 1.5 using ceil().
  • Line 8: We calculate the ceiling value of the negative number -5.5 using ceil().
  • Line 11: We calculate the ceiling value 0 using ceil().

Free Resources