string转换float

/// 
        /// string型转换为float型
        /// 

        /// 要转换的字符串
        /// 缺省值
        /// 转换后的int类型结果
        public static float StringToFloat(string strValue, float defValue = 0)
        {
            if ((strValue == null) || (strValue.Length > 10))
                return defValue;

            float intValue = defValue;
            if (strValue != null)
            {

                bool IsFloat = Regex.IsMatch(strValue, @"^([-]|[0-9])[0-9]*(\.\w*)?$");
                if (IsFloat)
                    float.TryParse(strValue, out intValue);
            }
            return intValue;
        }

你可能感兴趣的:(VSS)