Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

dart
ceil
math
communitycreator

What is the ceil() function in Dart?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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().

RELATED TAGS

dart
ceil
math
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring