Solved

Formating of int to string in six digit

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

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 25

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now