Dart .toInt()

VivianVanilla's avatar
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.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours

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

Contribute to Docs

Learn Dart on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours