ceil function

int? ceil(
  1. dynamic value
)

Returns the smallest integer greater than or equal to value.

  • Accepts int, double, or String.
  • Strings are parsed via parseDouble before applying .ceil().
  • Returns null if value is null.
  • Throws Exception if value is not a supported type.

Example:

ceil(3.2);      // -> 4
ceil("7.9");    // -> 8

Implementation

int? ceil(dynamic value) {
  if (value == null) return null;
  if (value is int) return value;
  if (value is double) return value.ceil();
  if (value is String) return parseDouble(value)?.ceil();
  throw Exception("Invalid value '$value' for 'ceil' function.");
}