Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

add a comma for thousands place -- in a string

I have this

Dim strNumber as string = 100000

msgbox(strNumber)

- the result i get is 100000

I want it to do this 100,000


How?
0
vbnetcoder
Asked:
vbnetcoder
  • 3
  • 2
1 Solution
 
Jacques Bourgeois (James Burger)PresidentCommented:
Ideally, since this is a numeric value, you should treat it as a number, not as a String:

Dim number As Integer = 100000

Where does your data comes from?

There are different ways to add the coma, depending on whether you get the data as a String or as an Integer, whether it is a fixed value as seems to be the case from your question, whether the value can change, whether you want to adjust the coma vs dot to the user's Control Panel.

What is your exact situation?
0
 
vbnetcoderAuthor Commented:
Actually to use your code to put a dollar space i would do this

number.tostring("C0")

In my case i don't want the dollar sign but i do want the comma.  How do i do that?  Basicly i need to replace "C0" with something else but not been able to find it.
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
With a number, you can use the following:

If you want to follow the Control Panel, which is the right way to do things in Windows for display purpose, use the following, using as many # and , necessary to apply to your biggest number:

Number.ToString("###,###")

This will show , on some computers, a space on others, depending on the Control Panel.

If you want to force a coma, which might be the case for a report or a text file, then force a display with the English conventions:

Number.ToString("###,###", New System.Globalization.CultureInfo("en"))
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"In my case i don't want the dollar sign but i do want the comma.  How do i do that?  Basicly i need to replace "C0" with something else but not been able to find it."

See "Standard Numeric Format Strings":
http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx

Use "N0" then:
        Dim number As Integer = 100000
        Dim strNumber As String = number.ToString("N0")

Open in new window


It will add the correct number of separators for you.
0
 
vbnetcoderAuthor Commented:
ty
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
Note that "N0" follows the Control Panel. It might give a coma on your computer, but a space or another character on another computer.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now