2

How to format a number 1000 to 1,000 for textbox to use in a Tostring in C# in a label and in a message.show

myString = "Attempt #" + AttemptNumber.ToString( );

AttemptsLbl.Text = AttemptNumber.ToString();

MessageBox.Show(" Match Found for All 3 Digits - it took " + AttemptNumber + " tries!");

johnyc
  • 23
  • 5
  • i hope i asked the right question idk even how to ask even tough i look online and read im kinda confuse how to ask or criteria programming is new to me – johnyc Apr 09 '17 at 00:42
  • thank you @bc004346 for editing im new to this how long have you code and how long does it take to be kinda knowledgeable about code i know i'm broad and general budi idk how to ask ? – johnyc Apr 09 '17 at 04:48
  • I've been at it for 15 years or so and I still have a lot to learn. But I do it for a living. To learn a specific language, a couple weeks. You should really learn and understand object oriented programming, and best practices to be effective. Then you can apply your knowledge with any language. Really, a couple years should do it :) Good luck! – djv Apr 09 '17 at 05:33
  • thank you so much i wanna build apps and i 'm doing c# right now but going to to go to android programming i wanna do this for a living and build or make apps for companies and myself :)) – johnyc Apr 09 '17 at 06:20

2 Answers2

1

Johnyc, You can use MyString = n.ToString("###,###"); for that.

Jim Simson
  • 2,774
  • 3
  • 22
  • 30
1

With this format #,##0, which can be used in either ToString or String.Format. When inserting the number in the middle of a string, I find String.Format more convenient. Both examples below.

myString = String.Format("Attempt #{0:#,##0}", AttemptNumber);
AttemptsLbl.Text = AttemptNumber.ToString("#,##0");
MessageBox.Show(String.Format("Match Found for All 3 Digits - it took {0:#,##0} tries!", AttemptNumber));

The format string from this Q&A: https://stackoverflow.com/a/295821/832052

Community
  • 1
  • 1
djv
  • 15,168
  • 7
  • 48
  • 72