if(var == 0)
a = String.Format("{0:D0}", i);
if(var == 1)
a = String.Format("{0:D1}", i);
if(var == 2)
a = String.Format("{0:D2}", i);
the format is variety by (var)
can i simply like this?
a = String.Format("{0:???}", i, var);
Thank you so much
a = string.Format("{0:D" + var.ToString() + "}", i);
"AhWau" <Ah...@discussions.microsoft.com> wrote in message
news:8CA23CD7-F5D8-4C6E...@microsoft.com...
You can't use a format inside a format. You can use another
String.Format call to format the format string:
a = String.Format(String.Format("{{0:D{0}}}", var), i)
or simply:
a = String.Format("{0:D" + var.ToString() + "}"), i)
Note:
From C# 3 var is a keyword, so don't use it for variable names...
--
Göran Andersson
_____
http://www.guffa.com
"AhWau" <Ah...@discussions.microsoft.com> wrote in message
news:8CA23CD7-F5D8-4C6E...@microsoft.com...
How about this?
NumberFormatInfo formatControl = new NumberFormatInfo();
formatControl.NumberDecimalDigits = var;
a = i.ToString(formatControl);
or
a = i.ToString("D", formatControl);
or
a = String.Format(formatControl, "{0:D}", i);
The NumberFormatInfo gives you a great deal of control over the output.
>
> Thank you so much
formatControl.NumberDecimalDigits = digits;
a = zahl.ToString(formatControl);
a = zahl.ToString("D", formatControl);
a = String.Format(formatControl, "{0:D}", zahl);
a = string.Format("{0:D" + digits.ToString() + "}", zahl);
What is the target?
1
--> 001
or --> 1,000?
or --> 1.000?
Only this works
a = string.Format("{0:D" + digits.ToString() + "}", zahl);
What is different between
string and String?
When I should use string and Stringbuilder?
Have someone a example?
Greeting Andreas
Which of these did you want? NumberFormatInfo has a lot of different
properties giving a lot more control than you get in the format string.
NumberDecimalDigits might have been the wrong thing to change.
If you want to use the local locale's decimal separator, use
Thread.CurrentCulture.NumberFormatInfo (or something like that) instead of
creating a new NumberFormatInfo object.
first:
1,99 ᅵ
second
1.99 ᅵ
third
00000456
4.
1,39453
1.39453
Greeting Andreas