简体   繁体   中英

Numeric Specifier for prefixing single digit with 0

I need to numeric format specifier, so as to prefix single digit with 0.

I need:

1=01
2=02
:
:
:
9=09

The two and three digits will remain as it is no changes

10=10
11=11
:
:

Try:

int nr = 1;
var result = nr.ToString("00");

result will be "01"

Use the PadLeft method for that

int number = 9;
string num = number.ToString().PadLeft(2, '0');

if your language is C# then you can use PadLeft(2, '0'); as like string a= '1' string b= a.PadLeft(2, '0') you answer will show 01 if need 1=001 then just use PadLeft(3, '0');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM