Converting String To Float in C#

后端 未结 7 737
渐次进展
渐次进展 2020-11-28 22:12

I am converting a string like \"41.00027357629127\", and I am using;

Convert.ToSingle(\"41.00027357629127\");

or

float.Pars         


        
7条回答
  •  一生所求
    2020-11-28 22:50

    Your thread's locale is set to one in which the decimal mark is "," instead of ".".

    Try using this:

    float.Parse("41.00027357629127", CultureInfo.InvariantCulture.NumberFormat);
    

    Note, however, that a float cannot hold that many digits of precision. You would have to use double or Decimal to do so.

提交回复
热议问题