GetDefaultFloatConversionValue() публичный статический Метод

Get default float conversion value
public static GetDefaultFloatConversionValue ( ) : float
Результат float
Пример #1
0
 /// <summary>
 /// Convert float string value in float value
 /// </summary>
 /// <param name="strValue">string to convert</param>
 /// <returns>float value</returns>
 public static float TryParseFloat(this string strValue)
 {
     return(strValue.TryParseFloat(
                BasePrimitivesExtensions.GetDefaultFloatConversionValue(),
                BasePrimitivesExtensions.GetDefaultFloatAllowDefaultConversion(),
                BasePrimitivesExtensions.GetDefaultFloatNumberStyle(),
                BasePrimitivesExtensions.GetCurrentCulture()));
 }
Пример #2
0
        /// <summary>
        /// Parse string array in float array
        /// </summary>
        /// <param name="strValue">string to parse</param>
        /// <param name="defaultValue">default value when default tryparse</param>
        /// <param name="allowDefaultConversion">Allow default tryparse values</param>
        /// <param name="numberStyle">number style to convert</param>
        /// <param name="culture">culture origin</param>
        /// <returns>float array</returns>
        public static float[] TryParseFloatArray(this string strValue, float[] defaultValue, bool allowDefaultConversion, NumberStyles numberStyle, CultureInfo culture)
        {
            if (String.IsNullOrEmpty(strValue))
            {
                return defaultValue ?? new float[] { }
            }
            ;

            var floatList = defaultValue != null
                ? defaultValue.ToList()
                : new List <float>();

            foreach (var l in strValue.Split(','))
            {
                var strFloat = l ?? "";

                if (String.IsNullOrEmpty(strFloat))
                {
                    if (allowDefaultConversion)
                    {
                        floatList.Add(BasePrimitivesExtensions.GetDefaultFloatConversionValue());
                    }

                    continue;
                }

                float floatConvert;
                if (!float.TryParse(strFloat, numberStyle, culture, out floatConvert))
                {
                    if (allowDefaultConversion)
                    {
                        floatList.Add(BasePrimitivesExtensions.GetDefaultFloatConversionValue());
                    }
                }
                else
                {
                    floatList.Add(floatConvert);
                }
            }

            return(floatList.ToArray());
        }
Пример #3
0
 /// <summary>
 /// Convert float string value in float value
 /// </summary>
 /// <param name="strValue">string to convert</param>
 /// <param name="numberStyle">number style to convert</param>
 /// <param name="culture">float culture origin</param>
 /// <returns>float value</returns>
 public static float TryParseFloat(this string strValue, NumberStyles numberStyle, CultureInfo culture)
 {
     return(strValue.TryParseFloat(BasePrimitivesExtensions.GetDefaultFloatConversionValue(),
                                   BasePrimitivesExtensions.GetDefaultFloatAllowDefaultConversion(),
                                   numberStyle, culture));
 }
Пример #4
0
 /// <summary>
 /// <para>Try parse float to float value</para>
 /// <para>Default value is BasePrimitivesExtensions.GetDefaultFloatConversionValue() value</para>
 /// </summary>
 /// <param name="objValue">object to convert</param>
 /// <returns>float result</returns>
 public static float TryParseFloat(this object objValue)
 {
     return(objValue.TryParseFloat(BasePrimitivesExtensions.GetDefaultFloatConversionValue()));
 }
Пример #5
0
 /// <summary>
 /// Convert nullable decimal value to float value
 /// </summary>
 /// <param name="decimalValue">nullable decimal value</param>
 /// <returns>float value</returns>
 public static float TryParseFloat(this decimal?decimalValue)
 {
     return(decimalValue.TryParseFloat(BasePrimitivesExtensions.GetDefaultFloatConversionValue()));
 }