padLeft method
Returns a string representation of this int, left-padded with zeroes if necessary to have the specified minimum number of characters.
If this int is negative, the negative sign is included in the number of characters.
Examples:
7.padLeft(3); // '007'
(-7).padLeft(3); // '-07'
1234.padLeft(3); // '1234'
Implementation
String padLeft(int minimumWidth) {
if (this < 0) {
var padded = (-this).padLeft(minimumWidth - 1);
return '-$padded';
}
return toString().padLeft(minimumWidth, '0');
}