.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

All contributors

Looking to contribute?

Learn Dart on Codecademy