Solved

length 10 in an integer in C#

Posted on 2009-07-09
7
474 Views
Last Modified: 2012-05-07
hi there, how do i actually declare or make an integer 10 in size .eg. 0000000001. ? in c#
0
Comment
Question by:doramail05
7 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24820691
what do u want to do with 0000000001 ?
0
 
LVL 20

Expert Comment

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

by:ddayx10
ID: 24820752
Sorry I wrote that last bit wrong:
        'Produces 000000001 if i=1
        'Produces 000000010 if i=10
         '...etc
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 39

Expert Comment

by:Pratima Pharande
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

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

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

Expert Comment

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
send messages to whatsapp programatically 2 48
Reset asp.net login password 4 42
Install Problem 13 31
Reference issues in Visual Studio 3 30
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question