数字说明符,用于以0作为单个数字的前缀
本文关键字:数字 单个 前缀 说明符 用于 | 更新日期: 2023-09-27 18:15:33
我需要一个数字格式说明符,以便在单个数字前加上0。
我需要:
1=01
2=02
:
:
:
9=09
两位和三位数字将保留,因为没有变化
10=10
11=11
:
:
尝试:
int nr = 1;
var result = nr.ToString("00");
result
将为"01"
使用PadLeft方法
int number = 9;
string num = number.ToString().PadLeft(2, '0');
如果你的语言是c#,那么你可以使用PadLeft(2, '0');就像string a= '1'
string b= a.PadLeft(2, '0')
一样,你的答案会显示01如果需要1=001,则使用PadLeft(3, '0');