Flutter Dart Convert String to Double Float Android iOS Example

As we all know Double data type is like parent of Float data type. In current programming arena most of developers use Double data type as place of Float data type. Dart gives us a inbuilt function named as double.parse(String) which is used to convert String numbered value to Double so the user can perform any type of mathematical operation on that value. So in this tutorial we would Flutter Dart Convert String to Double Float Android iOS Example Tutorial.

Contents in this project Flutter Dart Convert String to Double Float Android iOS Example Tutorial:

1. Import material.dart package in your app’s main.dart file.

2. Create void main runApp() method and here we would call our main MyApp class.

3. Creating our main MyApp extends StatelessWidget. This is our main Parent class.

4. Creating a String variable named as value1 with some random numbered string value.

5. Creating another variable named as value2 of Double data type. We would use this variable to store the converted value.

6. Creating a function named as changeType(). In this function we would use the double.parse() method to convert the String to double float value and then store the value in value2 variable. We would print the converted value on Terminal screen after done conversion.

7. Creating Widget Build area -> Material App widget -> Scaffold widget -> Center widget -> Column widget -> Raised Button widget. We would call the above changeType() function on Button click event.

8. Complete source code for main.dart file:

Screenshots:

Flutter Dart Convert String to Double Float Android iOS Example

Leave a Reply

Your email address will not be published. Required fields are marked *