Click here to Skip to main content
15,889,450 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im using c# and i need to add leading zeros without strings or padding
is it possible?

What I have tried:

i tried using google and x==x+"0" but it wont work
Posted
Updated 23-Mar-18 13:11pm
Comments
CPallini 24-Mar-18 17:18pm    
Numbers have no leading zeroes.

Padding only applies to a string representation of a number, so your question doesn't make much sense.

If that's what you're looking for, you can use a custom number formatting string:
C#
int x = 234;
Console.WriteLine("Value = " + x.ToString("000000"));

Value = 000234
 
Share this answer
 
v2
Comments
CPallini 24-Mar-18 17:17pm    
5.
Use
C#
string.ToString("D2") or string.ToString("D3")
...
The number value will vary.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900