Solved

Formating of int to string in six digit

Posted on 2010-08-30
5
540 Views
Last Modified: 2012-05-10
Hi,

I am working in web application C# using ASP.net3.5

I wanted to make any integer value to six digit

For example

- If int value is 120 then string value I need is 000120
- If int value is 35 then string value I need is 000035
- If int value is 3532 then string value I need is 003532

Can you please help me in formating this string


Many Thanks
0
Comment
Question by:tia_kamakshi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 166 total points
ID: 33559569
YourVariable.ToString("000000")
0
 
LVL 5

Accepted Solution

by:
makber earned 167 total points
ID: 33559589
int i = 555; // your integer variable
String.Format("{0:000000}", i);
0
 
LVL 26

Assisted Solution

by:Shaun Kline
Shaun Kline earned 167 total points
ID: 33559594
You can do this by using the PadRight string function:

int value = 120;
value.ToString().PadRight(6, "0");
0
 
LVL 4

Expert Comment

by:ricovox
ID: 33560730
any of the three above answers will work just fine. I suggest you choose the best answer for your particular application and divide the points.
0
 

Author Closing Comment

by:tia_kamakshi
ID: 33569731
Many Thanks for your support
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

738 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