|
-
Oct 14th, 2010, 04:53 PM
#1
Thread Starter
Hyperactive Member
Comma Separator
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.
SLEEP: A Totally Inadequate Substation For Caffeine!
-
Oct 14th, 2010, 05:05 PM
#2
Re: Comma Separator
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.
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("#,#"))
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.
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|