12,634,651 members (23,973 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 21: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 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 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

Top Experts
Last 24hrsThis month
 OriginalGriff 200 Richard MacCutchan 95 John Simmons / outlaw programmer 65 CPallini 65 ridoy 50
 OriginalGriff 2,374 ppolymorphe 1,271 Peter Leow 1,029 John Simmons / outlaw programmer 770 CPallini 686