floor function
Returns the largest integer less than or equal to value.
- Accepts
int,double, orString. - Strings are parsed via parseDouble before applying
.floor(). - Returns
nullifvalueisnull. - Throws Exception if
valueis not a supported type.
Example:
floor(3.9); // -> 3
floor("7.1"); // -> 7
Implementation
int? floor(dynamic value) {
if (value == null) return null;
if (value is int) return value;
if (value is double) return value.floor();
if (value is String) return parseDouble(value)?.floor();
throw Exception("Invalid value '$value' for 'floor' function.");
}