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
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.
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 ( .
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.
String s = i.toString().padLeft(2, '0');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With