Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
function zeroPad(num, places){ var zero = places - num.toString().length + 1; return Array(+(zero > 0 && zero)).join("0") + num; }
请告诉我上面代码的方法,以及如何在 C# 上使用它
该代码是 Javascript 并num用零填充数字的长度places,例如zeroPad(12, 4)给你0012。在 C# 中,您可以使用该PadLeft()方法执行此操作,例如12.ToString().PadLeft(4, '0'),它为您提供与上述相同的方法0012。
num
places
zeroPad(12, 4)
0012
PadLeft()
12.ToString().PadLeft(4, '0')