Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save an integer in two digits in Dart

Tags:

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

like image 613
Mangaldeep Pannu Avatar asked Mar 26 '19 14:03

Mangaldeep Pannu


People also ask

How do you declare an int in darts?

Numbers in Dart You declare instances of them using the keywords var, int, num or double. Use var if the variable can be dynamic and hold any type of variable. That's more or less as it is in JavaScript. Use int or double to explicitly declare the type of the variables.

How do you convert an int to a double in darts?

Convert int to double To convert an int to a double , use toDouble() method. The result is an integer with one decimal point ( . 0 ). The result is a double with one decimal point ( .

How do you double in darts?

Double − Dart also supports fractional numeric values i.e. values with decimal points. The Double data type in Dart represents a 64-bit (double-precision) floating-point number. For example, the value "10.10". The keyword double is used to represent floating point literals.


1 Answers

String s = i.toString().padLeft(2, '0');
like image 119
Alexandre Ardhuin Avatar answered Nov 16 '22 04:11

Alexandre Ardhuin