I'm trying to add zero-padding to a number. I did some searching and can't find an obvious way to do this. Am I missing something?
padStart() The padStart() method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length. The padding is applied from the start of the current string.
Inserting non-informative characters into a string is known as Padding. The insertion can be done anywhere on the string. String padding is useful for output formatting and alignment of strings while printing.
The standard way to add padding to a string in Python is using the str. rjust() function. It takes the width and padding to be used. If no padding is specified, the default padding of ASCII space is used.
You can use the String function .padLeft(Int width, [String = ' '])
https://api.dartlang.org/apidocs/channels/dev/dartdoc-viewer/dart-core.String#id_padLeft
int i = 2;
print(i.toString().padLeft(2, "0"));
result: 02
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