In this short article, let’s discuss how to show a number to two decimal places in Dart or any other decimal places in Dart.

First, you have to create a new Flutter project or you can try it yourself using the Dartpad.

void main() {
  double num1= 1.414548426;
  double num2=9.1548565;
  double num3=3.414525787;
  
  print(num1.toStringAsFixed(2)); //2 decimal places
  print(num2.toStringAsFixed(4)); //4 decimal places
  print(num3.toStringAsFixed(5)); //5 decimal places
  
}

Results:

1.41
9.1549
3.41453
Dartpad

Read more:

How to create a rounded tab bar in Flutter

What is Flutter?

How to create a simple application in the Flutter

Write A Comment