Pads a given number to the specified length.

Use Int32.ToString() with an appropriate format specifier, produced using string interpolation.

代码实现

public static partial class _30s 
{
  public static string PadNumber(int n, int length)
  {
    return n.ToString($"D{length}");
  }
}

使用样例

_30s.PadNumber(1234,6); // "001234"