Hi!
How can I insert commas in numbers.
For example, number is 123456789 , now I want that after inserting commas it should become 12,34,56,789....
how can i do this.......
vinnijain 0 Junior Poster
Recommended Answers
Jump to PostTry this :
int i = 123456789; //string s = i.ToString("##,##,##,###"); -->will not work string s = i.ToString("##-##-##-###"); // --> will work s = s.Replace('-', ',');
Jump to PostUse string Insert method:
int i = 1234567; string s = i.ToString(); for(int p=2; p < s.Length; p+=3) { s = s.Insert(p, ","); }
Jump to PostMy last snippet works for integers from 1 to MaxInt. Try it!
This snippet just tells you how it could be done. How it should be done is entirly up to you to decide.
Another possibility is the use of the SubString method and to concatenate all the substrings together …
All 12 Replies
colon3l 0 Newbie Poster
vinnijain 0 Junior Poster
ddanbe 2,724 Professional Procrastinator Featured Poster
vinnijain 0 Junior Poster
ddanbe 2,724 Professional Procrastinator Featured Poster
vinnijain 0 Junior Poster
ddanbe 2,724 Professional Procrastinator Featured Poster
vinnijain 0 Junior Poster
ddanbe 2,724 Professional Procrastinator Featured Poster
xcalibur37 0 Newbie Poster
HankReardon 0 Light Poster
Momerath 1,327 Nearly a Senior Poster Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.