Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 132,155 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,802 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
post 7 Oct, 2008 - 04:04 PM
Post #1


D.I.C Head

**
Joined: 6 Oct, 2008
Posts: 54

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

Go to the top of the page

nibbo
post 7 Oct, 2008 - 04:09 PM
Post #2


New D.I.C Head

*
Joined: 26 Aug, 2008
Posts: 15


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

Go to the top of the page

PsychoCoder
post 7 Oct, 2008 - 04:23 PM
Post #3


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,920



Thanked 117 times

Dream Kudos: 8475

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

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 online!Profile CardPM

Go to the top of the page

Qball522
post 7 Oct, 2008 - 04:39 PM
Post #4


D.I.C Head

**
Joined: 6 Oct, 2008
Posts: 54

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

Go to the top of the page

magicmonkey
post 7 Oct, 2008 - 04:58 PM
Post #5


D.I.C Regular

***
Joined: 12 Sep, 2008
Posts: 387



Thanked 64 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 online!Profile CardPM

Go to the top of the page

Qball522
post 7 Oct, 2008 - 05:03 PM
Post #6


D.I.C Head

**
Joined: 6 Oct, 2008
Posts: 54

TY very much!

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

Thank you, both of you.
User is offlineProfile CardPM

Go to the top of the page

modi123_1
post 7 Oct, 2008 - 05:57 PM
Post #7


D.I.C Addict

Group Icon
Joined: 12 Jun, 2008
Posts: 518



Thanked 10 times

Dream Kudos: 100
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 online!Profile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/21/08 01:55PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month