Convert the string to an Int in Dart
In this post we will give you information about Convert the string to an Int in Dart. Hear we will give you detail about Convert the string to an Int in DartAnd how to use it also give you demo for it if it is necessary.
we are going to learn about how to convert the string to an integer (Int) in Dart with the help of examples.
Consider, we have the following string in our code:
var a = "21"
Now, we need to convert the above string “21” to an integer 21.
Using int.parse() method
To convert a string to an integer, we can use the built-in int.parse() method in Dart.
The int.parse() function takes the string as an argument and converts it to the integer.
Here is an example, that converts the string “21” to an integer:
void main() { var a = "21"; var num = int.parse(a); // converts string to int print(num);}
Output:
21
Similarly, we can also convert the string to double by using the double.parse() method in Dart.
void main() { var a = "100.343"; var result = double.parse(a); // converts string to double print(result);}
Output:
100.343
Hope this code and post will helped you for implement Convert the string to an Int in Dart. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs