string to float
c# 中最高效的string to float
1 public float StrToFloat(object FloatString)
2 {
3 float result;
4 if (FloatString != null)
5 {
6 if (float.TryParse(FloatString.ToString(), out result))
7 return result;
8 else
9 {
10 return (float)0.00;
11 }
12 }
13 else
14 {
15 return (float)0.00;
16 }
17 }
2 {
3 float result;
4 if (FloatString != null)
5 {
6 if (float.TryParse(FloatString.ToString(), out result))
7 return result;
8 else
9 {
10 return (float)0.00;
11 }
12 }
13 else
14 {
15 return (float)0.00;
16 }
17 }
1 public float StrToFloat(object FloatString)
2 {
3 try
4 {
5 float f = (float)Convert.ToSingle(FloatString);
6 return f;
7 }
8 catch (FormatException)
9 {
10 return (float)0.00;
11 }
12 }
2 {
3 try
4 {
5 float f = (float)Convert.ToSingle(FloatString);
6 return f;
7 }
8 catch (FormatException)
9 {
10 return (float)0.00;
11 }
12 }