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 PostWell you could try converting your int into a string then format it the way you want...Anyway you just cant insert commas into a int type directly.
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, ","); }
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.