Parse string to float number C#

后端 未结 3 725
萌比男神i
萌比男神i 2020-12-11 02:18

I have float number in string. there is one problem. Number uses \".\" not \",\" as decimal point.

This code is not working:

MyNumber = float.Parse(\         


        
3条回答
  •  佛祖请我去吃肉
    2020-12-11 03:04

    Using string replace is very fragile, and will lead to suttle bugs. Specify the IFormatProvider instead. For instance:

    MyNumber = float.Parse("123.5", CultureInfo.InvariantCulture);
    

    Or you can specify the NumberFormatInfo using another overload of Parse.

提交回复
热议问题