Skip to main content
Added example
Source Link
tmaj
  • 35.8k
  • 12
  • 107
  • 143

Your profile says you're based in Brazil and in Brazil "two and a half" is "2,5", not "2.5".

If you run your code with "2,00" it should work.

Here's an example with different cultures:

foreach(var two in new []{"2.00", "2,00"})
foreach(var culture in new []{"pt-BR", "en-AU"})
{
    bool ok = int.TryParse(two, System.Globalization.NumberStyles.Float, new System.Globalization.CultureInfo(culture), out var i);
    Console.WriteLine($"For '{culture}' '{two}' is {(ok ? "OK" : "not OK")}");
}

This prints:

For 'pt-BR' '2.00' is not OK
For 'en-AU' '2.00' is OK
For 'pt-BR' '2,00' is OK
For 'en-AU' '2,00' is not OK

Your profile says you're based in Brazil and in Brazil "two and a half" is "2,5", not "2.5".

If you run your code with "2,00" it should work.

Your profile says you're based in Brazil and in Brazil "two and a half" is "2,5", not "2.5".

If you run your code with "2,00" it should work.

Here's an example with different cultures:

foreach(var two in new []{"2.00", "2,00"})
foreach(var culture in new []{"pt-BR", "en-AU"})
{
    bool ok = int.TryParse(two, System.Globalization.NumberStyles.Float, new System.Globalization.CultureInfo(culture), out var i);
    Console.WriteLine($"For '{culture}' '{two}' is {(ok ? "OK" : "not OK")}");
}

This prints:

For 'pt-BR' '2.00' is not OK
For 'en-AU' '2.00' is OK
For 'pt-BR' '2,00' is OK
For 'en-AU' '2,00' is not OK
Source Link
tmaj
  • 35.8k
  • 12
  • 107
  • 143

Your profile says you're based in Brazil and in Brazil "two and a half" is "2,5", not "2.5".

If you run your code with "2,00" it should work.