Hello Everyone:
I am trying to convert a number so that it has commas in it. If the number is 1234 it should be 1,234 or if its 1000000000 it will be 1,000,000,000.
Any Ideas?
Thanks
Art W.
Printable View
Hello Everyone:
I am trying to convert a number so that it has commas in it. If the number is 1234 it should be 1,234 or if its 1000000000 it will be 1,000,000,000.
Any Ideas?
Thanks
Art W.
Just to be clear, numbers don't contain commas. You can create a string representation of a number that contains commas, but the number itself has no format.
Now that we've got that out of the way, there are basically two format strings you can use: one standard and one custom.I threw one in there that doesn't add commas for contrast. If you want more information about those format strings then go the the MSDN Library and look up numeric format strings. There are similar topics for date and time.vb.net Code:
Dim n1 As Integer = 1234 Dim n2 As Integer = 1000000000 MessageBox.Show(n1.ToString("n0")) MessageBox.Show(n1.ToString("f0")) MessageBox.Show(n1.ToString("#,#")) MessageBox.Show(n2.ToString("n0")) MessageBox.Show(n2.ToString("f0")) MessageBox.Show(n2.ToString("#,#"))
Also, note that the comma in the "#,#" is the standard format marker for a thousand separator, but if the culture is set to one that uses a dot as a thousand separator then that is what will be displayed. Likewise, you ALWAYS use a dot in a format string to indicate a decimal separator, but it's the current culture that decides what actually gets displayed: a dot or a comma.