Newbie question - formatting a string

  • Thread starter Thread starter sefvgser
  • Start date Start date
S

sefvgser

I'd like to convert a number to a String. Is it possible to format my String
so that it contains some leading zeroes before the number?
e.g. if the number I want to convert is 12 then the String should be "0012"
if the number is 123 -> "0123" etc.
Rob
 
yup... in the ToString() method, try this:

int num = 123;
string display = num.ToString("00##");

HTH,
Bill P.
 
What about if its embedded as a String.Format specifier? There is an
inconsistency here [I think]

like DataBinder.Eval [in ASP.Net] has a third parameter that is passed to
string.Format as the format, if specified.

for example:
string costMessage = String.Format("Your cost is ${0:0.00} dollars.",
dollarAmount)
MessageBox.Show(costMessage, "Your Cost")

ps: please dont say "change it to Number.ToString()"
 
Eric Newton said:
What about if its embedded as a String.Format specifier? There is an
inconsistency here [I think]

like DataBinder.Eval [in ASP.Net] has a third parameter that is passed to
string.Format as the format, if specified.

for example:
string costMessage = String.Format("Your cost is ${0:0.00} dollars.",
dollarAmount)
MessageBox.Show(costMessage, "Your Cost")

ps: please dont say "change it to Number.ToString()"

I don't see the inconsistency here - could you try to explain it again
in a different way?
 
Sorry,

some of the previous context has been lost and I dont remember EXACTLY my
train of thought on this subject

but I believe it had something to do with being able to utilize
Decimal.ToString() in someplace that was declarative...

ug, I wish i could remember the original question

--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
(e-mail address removed)-software.com [remove the first "CC."]


Jon Skeet said:
Eric Newton said:
What about if its embedded as a String.Format specifier? There is an
inconsistency here [I think]

like DataBinder.Eval [in ASP.Net] has a third parameter that is passed to
string.Format as the format, if specified.

for example:
string costMessage = String.Format("Your cost is ${0:0.00} dollars.",
dollarAmount)
MessageBox.Show(costMessage, "Your Cost")

ps: please dont say "change it to Number.ToString()"

I don't see the inconsistency here - could you try to explain it again
in a different way?
 
Back
Top