11,791,059 members (48,197 online)
Rate this:
See more:
Convert.tostring() trims leftmost 0

ex.
int x= 01234
Convert.tostring(x)
results into 1234 and not 01234
Any suggestions
Thanks
Posted 14-Jan-13 20:08pm

Rate this:

## Solution 3

Integer values ignore all leading zeros: 01234 is teh same as 1234, is the same as 00000000000000000000000000001234
You need to format the ToString operation:
```int x = 01234;
Console.WriteLine(x.ToString());
Console.WriteLine(x.ToString("D5"));```
Will print:
```1234
01234```
Marcus Kramer at 15-Jan-13 9:50am

+5. This is the correct answer.
Rate this:

## Solution 4

integer variable will not consider Leading zeroes
so that
if you will assign
01234 to integer variable it will automatically save it in `x` variable as 1234

`string myString = String.Format("{0:00000}",x) // this will add leading zeros in a way that passed number will be have minimum 5 digits e.g. 123 -> 00123`
Happy coding!
Aarti Meswania at 16-Jan-13 0:12am

what is reason for downvote?
Rate this:

## Solution 2

You can use `TrimStart()`. So when you converted it to string
```string _YourText = "01234";
_YourText = _YourText.TrimStart(new Char[] { '0' } );```
--or--
`_YourText = _YourText.TrimStart('0');`
String.TrimStart Method In MSDN[^]

Good luck,
OI
v2
Rate this:

## Solution 1

HI,

you can use like this:

```String a = "000454332";
a=a.TrimStart('0');
int b = Convert.ToInt32(a);```

Thanks