Mangaldeep Pannu
Mangaldeep Pannu

Reputation: 3987

How to save an integer in two digits in Dart

How can I save an integer in two digits in Dart?

int i = 3;
String s = i.toString();
print(s);

The result should be 03 and not 3

Upvotes: 19

Views: 10137

Answers (2)

Steven Ogwal
Steven Ogwal

Reputation: 802

To save the first two digits of an integer.

 int val = 1546090;
 print(val);
 print(val.toString().substring(0,2));

Upvotes: -1

Alexandre Ardhuin
Alexandre Ardhuin

Reputation: 76333

String s = i.toString().padLeft(2, '0');

Upvotes: 66

Related Questions