欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

用 C# 将字符串转换为浮点数

最编程 2024-03-01 18:46:31
...
            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

 

推荐阅读