C#中将string转换为float

原文:https://www.cnblogs.com/tanrong/p/7074253.html

string s = "123.2";

            //方法1
            float f1 = Convert.ToSingle(s);

            //方法2
            float f2;
            if (!float.TryParse(s, out f2))
            {
                Console.WriteLine("无法转换!");
            } 

float volume = 0.5F; //double 转float

猜你喜欢

转载自blog.csdn.net/qq_33380252/article/details/85166035