Best way to parse float?

后端 未结 10 1098
无人及你
无人及你 2020-12-02 22:52

What is the best way to parse a float in CSharp? I know about TryParse, but what I\'m particularly wondering about is dots, commas etc.

I\'m having problems with my

10条回答
  •  悲哀的现实
    2020-12-02 23:01

    You could always use the overload of Parse which includes the culture to use?

    For instance:

    double number = Double.Parse("42,22", new CultureInfo("nl-NL").NumberFormat); // dutch number formatting
    

    If you have control over all your data, you should use "CultureInfo.InvariantCulture" in all of your code.

提交回复
热议问题