.toInt()
Published Apr 30, 2024
Contribute to Docs
In Dart, the .toInt()
method is used to convert numeric values, like doubles or strings representing numbers, to integers.
Syntax
numericValue.toInt()
Here, numericValue
can be any numeric value, such as a double or a string representing a number.
Example
In the following example, the .toInt()
method is used to convert the value of myNumber
from a double to an integer.
void main() {var myNumber = 10.4;var result = myNumber.toInt();print(result);}
The above code will generate the following output:
10
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.