提交 4c0056eb authored 作者: Thomas Mueller's avatar Thomas Mueller

Append a zero padded number.

上级 3053b2dd
...@@ -1009,4 +1009,28 @@ public class StringUtils { ...@@ -1009,4 +1009,28 @@ public class StringUtils {
return true; return true;
} }
/**
* Append a zero-padded number to a string builder.
*
* @param buff the string builder
* @param length the number of characters to append
* @param positiveValue the number to append
*/
public static void appendZeroPadded(StringBuilder buff, int length, long positiveValue) {
if (length == 2) {
if (positiveValue < 10) {
buff.append('0');
}
buff.append(positiveValue);
} else {
String s = Long.toString(positiveValue);
length -= s.length();
while (length > 0) {
buff.append('0');
length--;
}
buff.append(s);
}
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论