471,317 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

#,### problem

Hi,

In my C# Windows Form, I would like to input a number "1234" and the output
is "1,234".
What do I need to do?
Thanks for help.
Jason

Dec 26 '05 #1
4 1065
you can use Insert(int, string) on the string object.

string s = "1234";
s.Insert(1,",");

this solution will only work for 4 num char so to make it dynamic you will
have to use intelligent insert. You can use RegEx for that (e.g. for digits
like 100,000, or 1,200,000.34)
"Jason Huang" <Ja************@hotmail.com> wrote in message
news:el**************@TK2MSFTNGP14.phx.gbl...
Hi,

In my C# Windows Form, I would like to input a number "1234" and the
output is "1,234".
What do I need to do?
Thanks for help.
Jason

Dec 26 '05 #2
A better solution would be to convert the string to a number, using the
Parse method on the Int32 structure, and then to call the ToString method,
passing n or N for the format (which allows you to use group sizes).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Pohihihi" <no*****@hotmail.com> wrote in message
news:uE**************@TK2MSFTNGP15.phx.gbl...
you can use Insert(int, string) on the string object.

string s = "1234";
s.Insert(1,",");

this solution will only work for 4 num char so to make it dynamic you will
have to use intelligent insert. You can use RegEx for that (e.g. for
digits like 100,000, or 1,200,000.34)
"Jason Huang" <Ja************@hotmail.com> wrote in message
news:el**************@TK2MSFTNGP14.phx.gbl...
Hi,

In my C# Windows Form, I would like to input a number "1234" and the
output is "1,234".
What do I need to do?
Thanks for help.
Jason


Dec 26 '05 #3
Thanks!
Would you go into more details? Doesn't the C# already has an existing
class for this?

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> ¼¶¼g©ó¶l¥ó·s»D:%2****************@TK2MSFTNGP12.phx .gbl...
A better solution would be to convert the string to a number, using the
Parse method on the Int32 structure, and then to call the ToString method,
passing n or N for the format (which allows you to use group sizes).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Pohihihi" <no*****@hotmail.com> wrote in message
news:uE**************@TK2MSFTNGP15.phx.gbl...
you can use Insert(int, string) on the string object.

string s = "1234";
s.Insert(1,",");

this solution will only work for 4 num char so to make it dynamic you
will have to use intelligent insert. You can use RegEx for that (e.g. for
digits like 100,000, or 1,200,000.34)
"Jason Huang" <Ja************@hotmail.com> wrote in message
news:el**************@TK2MSFTNGP14.phx.gbl...
Hi,

In my C# Windows Form, I would like to input a number "1234" and the
output is "1,234".
What do I need to do?
Thanks for help.
Jason



Dec 26 '05 #4
Hi Jason,

That was what Nicholas said. If you have a string represenation of a
number "1234", then you need to parse it to an int (Int32)

int n = Int32.Parse("1234");

However, once you have the number, simply call ToString() on the number,
specifying the format as N or N0 (zero, indicating the number trailing
zeroes, default is 2)

MessageBox.Show( n.ToString( "N" ) );

--
Happy Coding!
Morten Wennevik [C# MVP]
Dec 26 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Kostatus | last post: by
117 posts views Thread by Peter Olcott | last post: by
18 posts views Thread by Ian Stanley | last post: by
28 posts views Thread by Jon Davis | last post: by
6 posts views Thread by Ammar | last post: by
2 posts views Thread by Mike Collins | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.