Bugg when parsing string to int

  • Thread starter Thread starter Henke
  • Start date Start date
H

Henke

Is this a bug or is there a reason why it doesn't work.
int i = int.Parse("4 500");

I ask because this works:
double d = double.Parse("4 500.0");

Thanks!
/Henkr
 
Henke said:
Is this a bug or is there a reason why it doesn't work.
int i = int.Parse("4 500");

I ask because this works:
double d = double.Parse("4 500.0");

The latter doesn't work for me... could you give a short but complete
example where it does work? Here's one which shows it failing for me:

using System;
class Test
{
static void Main()
{
Console.WriteLine (double.Parse ("4 500.0"));
}
}
 
Henke said:
Is this a bug or is there a reason why it doesn't work.
int i = int.Parse("4 500");

I ask because this works:
double d = double.Parse("4 500.0");

^his looks like a localization thingie
Where the thousands seperator is a space.
No idea why the int doesn't work too, though.
 
Henke said:
It's like Ayende says, in sweden we use space as thousands separator.

Well, if you look at the docs closely, you'll see both are behaving
exactly as specified - Double.Parse specifies that grouping characters
are allowed, whereas Int32.Parse just talks about optional whitespace,
an optional sign, and then a series of digits 0-9.

As to why the grouping character isn't allowed in Int32.Parse, I don't
know - but both do appear to be working as designed.
 
You are so right, now it's up to me to do the hard work of removing the
ws...

Thanks!
/Henke
 
Back
Top