The `truncate` method in Dart returns this truncated to an integer.
The syntax of int.truncate() method is:
int truncate()
This truncate() method of int returns this.
int.truncate() returns value of type int
.
In this example,
integerNum
with the value 7, which is already an integer.truncate()
method to get its integer value, which remains the same as it's already an integer.void main() {
int integerNum = 7;
int truncInteger = integerNum.truncate();
print('Truncate of $integerNum: $truncInteger');
}
Truncate of 7: 7
In this Dart tutorial, we learned about truncate() method of int: the syntax and few working examples with output and detailed explanation for each example.