Solved

add a comma for thousands place -- in a string

Posted on 2014-02-22
6
289 Views
Last Modified: 2014-02-27
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
Comment
Question by:vbnetcoder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 40
ID: 39879357
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
 

Author Comment

by:vbnetcoder
ID: 39879365
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
 
LVL 40
ID: 39879416
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 39879448
"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
 

Author Closing Comment

by:vbnetcoder
ID: 39892951
ty
0
 
LVL 40
ID: 39893003
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

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question