Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 244,296 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 859 people online right now. Registration is fast and FREE... Join Now!




Comma's

 
Reply to this topicStart new topic

Comma's, How do you display commas in values.

Qball522
7 Oct, 2008 - 04:04 PM
Post #1

D.I.C Head
**

Joined: 6 Oct, 2008
Posts: 57

I was wondering if there is a simple way of displaying 1,000,000 instead of 1000000.

What would you have to do in order to break the number up to make it easier to read larger numbers.

I am sure I could come up with some sort of an IF statement to handle it, but that seems to be an overkill for this.

User is offlineProfile CardPM
+Quote Post


nibbo
RE: Comma's
7 Oct, 2008 - 04:09 PM
Post #2

New D.I.C Head
*

Joined: 26 Aug, 2008
Posts: 24


My Contributions
QUOTE(Qball522 @ 7 Oct, 2008 - 05:04 PM) *

I was wondering if there is a simple way of displaying 1,000,000 instead of 1000000.

What would you have to do in order to break the number up to make it easier to read larger numbers.

I am sure I could come up with some sort of an IF statement to handle it, but that seems to be an overkill for this.


Use FormatNumber

User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Comma's
7 Oct, 2008 - 04:23 PM
Post #3

loves.Coding(this);
Group Icon

Joined: 26 Jul, 2007
Posts: 12,283



Thanked: 372 times
Dream Kudos: 10775
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Stay away from FormatNumber(), this is a legacy function left over from the VB6 days, stick with the native libraries within the .Net Library. There are a couple way of accomplishing this with String.Format(). Here are a couple examples

vb

Dim i As Integer = 1000000
Console.WriteLine(String.Format("{0:0,0}",i)
'This result would be 1,000,000


vb

Dim i As Integer = 1000000
Console.WriteLine(String.Format("{0:#,#}",i)
'This result would be 1,000,000


vb

Dim i As Integer = 1000000
Console.WriteLine(String.Format("{0:n}",i)
'This result would be 1,000,000



You could also use ToString() and pass in the same formats:

vb

Dim i As Integer = 1000000
Console.WriteLine(i.ToString("#,#")
'This result would be 1,000,000


Hope that helps smile.gif
User is offlineProfile CardPM
+Quote Post

Qball522
RE: Comma's
7 Oct, 2008 - 04:39 PM
Post #4

D.I.C Head
**

Joined: 6 Oct, 2008
Posts: 57

When I tried to use all of those they still gave me 1000000.

All I did was Button_Click (inserted the code you provided) and tried to output that number in a label and a Msgbox and still gave me no comma's.

I am new to VB, well I am new to programming all together, about the only thing I know well is Basic, and that was in high school.

Edit: On a side note PsychoCoder, I hope you are doing something great with your gift of programming. Even if its not great to someones standards, I at least hope your wallet is getting fat from it.

This post has been edited by Qball522: 7 Oct, 2008 - 04:41 PM
User is offlineProfile CardPM
+Quote Post

magicmonkey
RE: Comma's
7 Oct, 2008 - 04:58 PM
Post #5

D.I.C Regular
***

Joined: 12 Sep, 2008
Posts: 484



Thanked: 93 times
My Contributions
Well you can't copy exactly what he wrote, that is just an example. To use it with a textbox...

vb

Dim i as Integer = 1000000
textbox1.Text = String.Format("{0:0,0}",i)
'Or
textbox1.Text = i.ToString("0,0")


That help?
User is offlineProfile CardPM
+Quote Post

Qball522
RE: Comma's
7 Oct, 2008 - 05:03 PM
Post #6

D.I.C Head
**

Joined: 6 Oct, 2008
Posts: 57

TY very much!

I didn't know what the command he used.. ><

Thank you, both of you.
User is offlineProfile CardPM
+Quote Post

modi123_1
RE: Comma's
7 Oct, 2008 - 05:57 PM
Post #7

Suiter #2
Group Icon

Joined: 12 Jun, 2008
Posts: 1,216



Thanked: 49 times
Dream Kudos: 150
My Contributions
What about the 'masked textbox' that comes standard in the toolbox? You input a number mask and budda-bing-badda-boom.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 04:41PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month