C# string转换为float

           string str = "0.82";
 
            //方法1
            float f1 = Convert.ToSingle(str);
 
            //方法2
            float f2;
            if (!float.TryParse(str, out f2))
            {
                Console.WriteLine("转换错误!");
            } 

 

float threshold= 0.82f; //double 转float

 

posted @ 2022-04-01 09:34  qingjiawen  阅读(221)  评论(0编辑  收藏  举报