常用函数总结:
1.string转float:
string temp1 = 6.666;
float temp2 = 0;
temp2 = Convert.Tosingle(temp1);
运行后可得temp2 = 6.666;
2.取小数点后固定位数
float temp = 6.666;
temp = (float)Math.Round(temp,2);
运行后可得temp = 6.66;
本文介绍如何在C#中将字符串转换为浮点数,并演示了如何使用Math.Round方法限制浮点数的小数位数。这对于需要精确控制数值显示的应用场景非常有用。
常用函数总结:
1.string转float:
string temp1 = 6.666;
float temp2 = 0;
temp2 = Convert.Tosingle(temp1);
运行后可得temp2 = 6.666;
2.取小数点后固定位数
float temp = 6.666;
temp = (float)Math.Round(temp,2);
运行后可得temp = 6.66;
282

被折叠的 条评论
为什么被折叠?