The `toInt` method in Dart truncates this number to an integer and returns the result as an integer.
The syntax of int.toInt() method is:
int toInt()
This toInt() method of int truncates this num to an integer and returns the result as an int.
int.toInt() returns value of type int
.
In this example,
num1
with the value 10.toInt()
method to convert it to an integer.void main() {
int num1 = 10;
int result1 = num1.toInt();
print('Integer value of $num1: $result1');
}
Integer value of 10: 10
In this example,
num2
with the value 0.toInt()
method to convert it to an integer.void main() {
int num2 = 0;
int result2 = num2.toInt();
print('Integer value of $num2: $result2');
}
Integer value of 0: 0
In this example,
num3
with the value -7.toInt()
method to convert it to an integer.void main() {
int num3 = -7;
int result3 = num3.toInt();
print('Integer value of $num3: $result3');
}
Integer value of -7: -7
In this Dart tutorial, we learned about toInt() method of int: the syntax and few working examples with output and detailed explanation for each example.