Dart toInt() Method

Last updated on February 21, 2023

The toInt() method converts non-integer values into integers. It doesn’t accept any parameters and returns value with integer data type.




The toInt() method doesn’t need any parameter, it attaches with a value or variable to convert into the integer.

Example 1

Let’s say we have a float value,


To convert into integer, attach the toInt() method.

// Output: 65

You can also wrap the value with parenthesis,

// Output: 65

In this example, the toInt() method is attached with a float value which is converted into an integer. Therefore we got 65 in the output. You can use the print() function to see the result in the console.


Example 2

Create a variable and store a float value.

var floatValue = 30.15;

To convert into integer, attach the toInt() method with floatValue variable which can be accessed through dot notation.

// Output: 30

To see the result in the console, use print() function.


Written by
I am a skilled full-stack developer with extensive experience in creating and deploying large and small-scale applications. My expertise spans front-end and back-end technologies, along with database management and server-side programming.

Share on:

Related Posts