Solved

# length 10 in an integer in C#

Posted on 2009-07-09
470 Views
hi there, how do i actually declare or make an integer 10 in size .eg. 0000000001. ? in c#
0
Question by:doramail05

LVL 29

Expert Comment

ID: 24820691
what do u want to do with 0000000001 ?
0

LVL 20

Expert Comment

ID: 24820732
You can't exactly do that. As you have probably seen if you supply an integer the value 00001 it will be 1 because that is numerically what you are giving it. An integer will not hold places as a data type it will store the value you supply it.

Now for display purposes you can cause an integer to display on the screen that way using string custom formatting like this (sorry close as I can get'cha).

EX.

Dim i As Integer = 10

Dim j As String = i.ToString("000000000")

Response.Write(j)

'Produces 000000010 if i=1
'Produces 000000010 if i=10
0

LVL 20

Expert Comment

ID: 24820752
Sorry I wrote that last bit wrong:
'Produces 000000001 if i=1
'Produces 000000010 if i=10
'...etc
0

LVL 39

Expert Comment

ID: 24820753
int num;
num = 1;
Response.Write(string.Format("{0:0000000000}",num));

try this

when you give input 1 it will add 9 0's before it

if you giove 12 it will add 8 0's before it
0

LVL 18

Accepted Solution

philipjonathan earned 500 total points
ID: 24820755
Variables of type int are able to store value from -2,147,483,648 to 2,147,483,647, so you can use it to store 10 digits integer data.

To display it with 0-padding, you can use the formatting options, example:
int i = 123;
string format = "0000000000";
Console.WriteLine(i.ToString(format));

That will output:
0000000123
0

LVL 20

Expert Comment

ID: 24820898
LOL lots of same thing....must be on the right track :)
0

LVL 20

Expert Comment

ID: 24828859
I can't even imagine how you chose to award the points here, but alas...win some/lose some I suppose.
0

## Featured Post

### Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…