I would like to emulate C's sprintf("%02d", x);
in Dart, but I can't find string formatting, only string interpolation.
String interpolation covers most of your needs. If you want to format numbers directly, there is also num.toStringAsPrecision()
.
I took a different approach to this issue: by padding the string directly, I don't have to use any libraries (mainly because the intl library seems to be discontinued):
x.toString().padLeft(2, "0");
Would be the equivalent of sprintf("%02d", x);
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