user240141
user240141

Reputation:

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
:
:

Upvotes: 0

Views: 801

Answers (3)

Arefin Hasan Bhuiyan
Arefin Hasan Bhuiyan

Reputation: 11

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');

Upvotes: 0

M P
M P

Reputation: 2337

Use the PadLeft method for that

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

Upvotes: 1

Rafal
Rafal

Reputation: 1091

Try:

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

result will be "01"

Upvotes: 6

Related Questions