Solved

Formating of int to string in six digit

Posted on 2010-08-30
5
542 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

696 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