Round A Double Number in Flutter DART After Decimal

Hello friends, First of all Happy New year. I know it’s been late but I was busy then. Now let’s come to the main point, In today’s tutorial we would learn about Dart Math inbuilt functions round(), roundToDouble(). We would also discuss another method in which If user creates Float number using var declaration. Then it does not properly works as a Double then above round and round to double methods will not work on it. Now to work it properly we have to convert first it into string and setting up 2 Decimal after point then again convert it into double. I have explained all the work here in this tutorial so you don’t have to worry about it. So in this tutorial we would learn about Round A Double Number in Flutter DART After Decimal.

Contents in this project Round A Double Number in Flutter DART After Decimal :-

1. Open your project’s main.dart file and import material.dart package.

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

3. Creating MyApp extends StatelessWidget, our main class.

4. Creating 2 Double float variables using double and var syntax. We would convert them one by one in a function.

5. Creating a function named as roundNumbers(). In this function first we would use the round() method to convert the number to it’s closest integer value in round format. In next step we would use the roundToDouble() method to convert the number to its closest double number. We would also covnerting the var variable to string then in Double.

6. Creating Widget Build area -> here we would make 1 Button widget and call the above function on onPress event.

7. Complete source code for main.dart file :-

Screenshot :-

Round A Double Number in Flutter DART After Decimal

Leave a Reply

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