Solved

Formating of int to string in six digit

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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