Label.Text / Convert.ToString And String.Format Help / Thousand Separator
I have a label that i want to show it's Text("1234567")
Like A Number With Th开发者_运维百科ousand Separator//
how can i do this with :
Lable1.Text = string.Format(.....;
Lable1.Text = Convet.ToString(.....;
please explain these two.
For IFormatProvider information relating to numbers (for use with Convert.ToString(...,IFormatProvider)
), see the remarks section here. You can follow the links to NumberGroupSeparator and other formatting options which have some example code.
String.Format
also can take an IFormatProvider, but it also understands other formatting directly supplied as a string. See the remarks section of the String Format method -- once again you can follow the links to areas of interest like Standard Numerical Formatting which has an example of internationalized "," numbers.
Happy reading.
Addition in response to comment
IFormatProvider is an interface; NumberFormatInfo is one provider. That is, you can specify the format arguments to a new NumberFormatInfo object and pass that as the IFormatProvider. You can see there is a whole host of members you can twiddle with: NumberFormatInfo members. The advantage of an IFormatProvider is that you can create and define your own conversion formats. You can even invoke the Format
method of an ICustomFormatter directly, if you wish -- with some omissions, this is about what String.Format
does for you. You may also be interested in CultureInfo.CurrentCulture.
Dim Num As Integer = 1234567
Label1.Text = Num.ToString("n0")
精彩评论