/// <summary> /// 将字符串数据转换为int数据,如果格式不对则返回0 /// </summary> /// <param name="str">需要转换的字符串</param> /// <returns></returns> public static int String2Int(string str) { int i = 0; int.TryParse(str, out i); return i; } /// <summary> /// 将字符串数据转换为double数据,如果格式不对则返回0 /// </summary> /// <param name="str">需要转换的字符串</param> /// <returns></returns> public static double String2Double(string str) { double d = 0.0; double.TryParse(str, out d); return d; } /// <summary> /// 将字符串数据转换为float数据,如果格式不对则返回0 /// </summary> /// <param name="str">需要转换的字符串</param> /// <returns></returns> public static float String2Float(string str) { float f = 0; float.TryParse(str, out f); return f; }
标签:返回,string,int,double,float,str,字符串 From: https://www.cnblogs.com/lin-07/p/18072848