padNumber static method
Implementation
static String padNumber(num value, int len)
{
// Supports signed numbers.
bool isNegative = value < 0;
if (isNegative) {
value = value.abs();
}
// At least this many, handling 0 case.
int valueDigits = ( value==0 ? 0 : Math.log10(value).floor() ) + 1;
StringBuffer sb = new StringBuffer();
if (isNegative) {
sb.write("-");
}
sb.write( (
// Pad zeros, at least as much as value.
value + Math.pow(10,
// Pad at least as much as length of value.
Math.max(len, valueDigits) )
)
.toString()
.substring(1) );
return sb.toString();
}