473,326 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Can Convert.Int32 handle Thousands separator?

I want to know if a call to Convert.Int32 can handle a Culture specific
string.

I have the following code:

string sText = "111,111,111";
int i;

i = Convert.Int32( sText );

This throws an exception.

So I try adding the following:

CultureInfo ci = Thread.CurrentThread.CurrentCulture;

i = Convert.Int32( sText, ci.NumericInfo );

This also throws.

Do I have to remove the Thousands Separator character myself?
Nov 15 '05 #1
3 7741
Hi Tim,

Suggest:

string sText = "111,111,111";
int i;

i = Int32.Parse(sText, NumberStyles.AllowThousands);

Regards,
Dan

"Tim Osborne" <Ti*********@xcellenet.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I want to know if a call to Convert.Int32 can handle a Culture specific
string.

I have the following code:

string sText = "111,111,111";
int i;

i = Convert.Int32( sText );

This throws an exception.

So I try adding the following:

CultureInfo ci = Thread.CurrentThread.CurrentCulture;

i = Convert.Int32( sText, ci.NumericInfo );

This also throws.

Do I have to remove the Thousands Separator character myself?

Nov 15 '05 #2
Tim,

On the culture you are using, check the NumberFormat property. On the
NumberFormatInfo instance returned, check the NumberGroupSeparator property
to see the character used to separate groups.

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

"Tim Osborne" <Ti*********@xcellenet.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I want to know if a call to Convert.Int32 can handle a Culture specific
string.

I have the following code:

string sText = "111,111,111";
int i;

i = Convert.Int32( sText );

This throws an exception.

So I try adding the following:

CultureInfo ci = Thread.CurrentThread.CurrentCulture;

i = Convert.Int32( sText, ci.NumericInfo );

This also throws.

Do I have to remove the Thousands Separator character myself?

Nov 15 '05 #3
I got there about the same time as you did.

Actually I went with NumberStyles.Number.

Thanks a lot for the quick response though.

"Daniel Pratt" <ko******************@hotmail.com> wrote in message
news:uh**************@TK2MSFTNGP12.phx.gbl...
Hi Tim,

Suggest:

string sText = "111,111,111";
int i;

i = Int32.Parse(sText, NumberStyles.AllowThousands);

Regards,
Dan

"Tim Osborne" <Ti*********@xcellenet.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I want to know if a call to Convert.Int32 can handle a Culture specific
string.

I have the following code:

string sText = "111,111,111";
int i;

i = Convert.Int32( sText );

This throws an exception.

So I try adding the following:

CultureInfo ci = Thread.CurrentThread.CurrentCulture;

i = Convert.Int32( sText, ci.NumericInfo );

This also throws.

Do I have to remove the Thousands Separator character myself?


Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Douglas | last post by:
Gday, How would I format a number so that: TheValue = 32500 Displays in the TextBox as: $32,500.00
2
by: Alberto | last post by:
I have in a int32 a value and a want to show it in a label in this format: 1,234. I know there is an overload to the ToString method who has a string format. Which is string to see the numbers with...
1
by: Woodies_46 | last post by:
Ok i know this is simple but i just don't know the syntax. What I have is a bunch of values and i want to be able to display them as money values with a $ in front. eg. 16000000 1000 160000
4
by: Joao Tomas | last post by:
Please, can someone help me to translate this single function to VB.NET ? ' DECLARATIONS Private Const BMP_MAGIC_COOKIE As Short = 19778 Private Structure BITMAPFILEHEADER '14 bytes...
11
by: Yaniv | last post by:
Hi How can I convert Uint32 variable to System.drawing.color ?? Thanks in advanced Yaniv
8
by: =?Utf-8?B?V2hpdG5leSBLZXc=?= | last post by:
Hi there, I'm having a bit of trouble using an HRASCONN object as a class member variable inside my managed C++ class. When I call RasDial() and pass in the address of my HRASCONN object, I get...
2
by: Nicolai.Schoenberg | last post by:
When i try it like you say, he ignores the dot. For example s = "12.45"; d = double.Parse(s); d will be 1245.0 :( pls help
0
by: Piotrekk | last post by:
Hi I have an dword array returned by send message with TBM_GETPTICS Message. Thus i need to convert IntPtr to managed block of memory ( Int32 because od dword ). I tried saveral ways but it...
4
by: Yoavo | last post by:
Hi, I want to convert a string to double. I use the function: "System.Convert.ToDouble". The problem is that if the string contains the character "." the program aborts. What might be the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.