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.
我目前将整数转换为字符串以显示在屏幕上,但希望保持 4 位数字 - 即 10 =“0010”。从整数 10 到字符串“0010”的最佳方法是什么?
这是在 C# 和 .NET 4 中。
干杯!
int num = 1; // pad with 0 up to 4 places string str = num.ToString("D4");
var str = 10.ToString("0000");
你可以试试 :-
string str = num.ToString("D8"); //padding with 8 zero's
检查此链接