Why do I get a FormatException when converting a string to a float?

后端 未结 7 1504
傲寒
傲寒 2021-02-19 06:46

When I try to convert a string to float:

Console.WriteLine(float.Parse(\"6.59\"));

it throws an exception:

Unhandled Exc

相关标签:
7条回答
  • 2021-02-19 07:14

    You are probably using a culture that uses the , as a decimal seperator.

    You could try to Parse using the InvariantCulture:

    float.Parse("6.59", CultureInfo.InvariantCulture)
    
    0 讨论(0)
提交回复
热议问题