ToDouble() public static method

public static ToDouble ( DateTime value ) : double
value DateTime
return double
Example #1
0
        /// <summary>
        /// Loads a matrix from a file to a double[][] array.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public static double[][] LoadMatrix(string fileName)
        {
            string[] allLines = System.IO.File.ReadAllLines(fileName);

            double[][] matrix = new double[allLines.Length][];

            for (int i = 0; i < allLines.Length; i++)
            {
                string[] values = allLines[i].Split(',');
                matrix[i] = new double[values.Length];

                for (int j = 0; j < values.Length; j++)
                {
                    if (values[j] != "")
                    {
                        matrix[i][j] = Convert.ToDouble(values[j]);
                    }
                    else
                    {
                        matrix[i][j] = Double.NaN;
                    }
                }
            }

            return(matrix);
        }
Example #2
0
        public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
        {
            Object res = new Object();

            String[] xpr = SysConvert.ToString(parameter).Split('|');

            switch (xpr[0])
            {
            case "+":
                res = SysConvert.ToDouble(value) + SysConvert.ToDouble(xpr[1]);
                break;

            case "-":
                res = SysConvert.ToDouble(value) - SysConvert.ToDouble(xpr[1]);
                break;

            case "*":
                res = SysConvert.ToDouble(value) * SysConvert.ToDouble(xpr[1]);
                break;

            case "/":
                res = SysConvert.ToDouble(value) / SysConvert.ToDouble(xpr[1]);
                break;
            }

            return(res);
        }
Example #3
0
        private void LoadVariables()
        {
            Prefix        = Convert.ToString(GetConfig("Chat Settings", "Prefix", "[NightPVP] "));               // CHAT PLUGIN PREFIX
            PrefixColor   = Convert.ToString(GetConfig("Chat Settings", "PrefixColor", "#bf0000"));              // CHAT PLUGIN PREFIX COLOR
            ChatColor     = Convert.ToString(GetConfig("Chat Settings", "ChatColor", "#dd8e8e"));                // CHAT MESSAGE COLOR
            SteamIDIcon   = Convert.ToUInt64(GetConfig("Chat Settings", "SteamIDIcon", "76561198079320022"));    // SteamID FOR PLUGIN ICON - STEAM PROFILE CREATED FOR THIS PLUGIN / NONE YET /
            starthour     = Convert.ToSingle(GetConfig("Night Time Zone", "Start at", "21"));
            stophour      = Convert.ToSingle(GetConfig("Night Time Zone", "Stop at", "6"));
            leftmin       = Convert.ToDouble(GetConfig("HUD position", "left (0.95 by default)", "0.95"));
            bottom        = Convert.ToDouble(GetConfig("HUD position", "bottom (0.86 by default)", "0.86"));
            HUDtxtsize    = Convert.ToInt32(GetConfig("HUD text size", "(10 by default)", "10"));
            HUDwidth      = Convert.ToDouble(GetConfig("HUD size", "width (0.05 by default)", "0.05"));
            HUDheigth     = Convert.ToDouble(GetConfig("HUD size", "heigth (0.04 by default)", "0.04"));
            HUDpvecolor   = Convert.ToString(GetConfig("HUD color", "for PVE", "0.5 1.0 0.0"));              // CHAT MESSAGE COLOR
            HUDpveopacity = Convert.ToString(GetConfig("HUD opacity", "for PVE", "0.0"));                    // CHAT MESSAGE COLOR
            HUDpvpcolor   = Convert.ToString(GetConfig("HUD color", "for PVP", "0.85 0.2 0.5"));             // CHAT MESSAGE COLOR
            HUDpvpopacity = Convert.ToString(GetConfig("HUD opacity", "for PVP", "0.0"));                    // CHAT MESSAGE COLOR

            //rate = Convert.ToSingle(GetConfig("", "", "300"));

            if (!ConfigChanged)
            {
                return;
            }
            SaveConfig();
            ConfigChanged = false;
        }
        /// <summary>
        /// Converts a value to a <see cref="double"/>.
        /// </summary>
        /// <param name="value">The object to convert.</param>
        /// <returns>The converted <paramref name="value"/>.</returns>
        public double ToDouble(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            return(SConvert.ToDouble(value, CultureInfo.InvariantCulture));
        }
Example #5
0
        /// <summary>
        /// Creates the range.
        /// </summary>
        /// <param name="highEu">The high engineering unit.</param>
        /// <param name="lowEu">The low engineering unit.</param>
        /// <returns></returns>
        public static Range CreateRange(ItemProperty highEu, ItemProperty lowEu)
        {
            Range rng = new Range()
            {
                High = Convert.ToDouble(highEu.Value),
                Low  = Convert.ToDouble(lowEu.Value)
            };

            return(rng);
        }
Example #6
0
 /// <summary>
 /// 将指定的 <see cref="IConvertible"/> 数字转换为其对应的对数。
 /// </summary>
 /// <param name="value">要转换的 <see cref="IConvertible"/> 数字。</param>
 /// <param name="targetType">绑定目标属性的类型。</param>
 /// <param name="parameter">表示对数的底的转换器参数。默认为常数 <see langword="e"/>。</param>
 /// <param name="culture">要用在转换器中的区域性。</param>
 /// <returns><paramref name="value"/> 的底为 <paramref name="parameter"/> 的对数。</returns>
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     try
     {
         var number = Convertible.ToDouble(value ?? 0.0, culture);
         var @base  = Convertible.ToDouble(parameter ?? Math.E, culture);
         var result = Math.Log(number, @base);
         return(Convertible.ChangeType(result, targetType, culture));
     }
     catch (Exception) { return(DependencyProperty.UnsetValue); }
 }
Example #7
0
        public static string GetBlogPagination(BlogSettings settingsItem, int currentPage, int totalRows, int maximumRows)
        {
            StringBuilder pagination = new StringBuilder();

            double decMaxPages = Convert.ToDouble(totalRows) / Convert.ToDouble(maximumRows);
            int    maxPages    = Convert.ToInt32(Math.Ceiling(decMaxPages));

            if (maxPages > 1)
            {
                if (currentPage > maxPages)
                {
                    // outside our range, make first page
                    currentPage = 1;
                }

                if (currentPage != 1)
                {
                    pagination.Append(String.Format("<a href=\"?{0}={1}\">{2}</a> ", XBSettings.XBPageQS, "1", settingsItem.FirstPageText));
                    pagination.Append(String.Format("<a href=\"?{0}={1}\">{2}</a> ", XBSettings.XBPageQS, Convert.ToString(currentPage - 1), settingsItem.PreviousPageText));
                }

                if (currentPage - 2 > 0)
                {
                    pagination.Append(String.Format("<a href=\"?{0}={1}\">{2}</a> ", XBSettings.XBPageQS, Convert.ToString(currentPage - 2), Convert.ToString(currentPage - 2)));
                }

                if (currentPage - 1 > 0)
                {
                    pagination.Append(String.Format("<a href=\"?{0}={1}\">{2}</a> ", XBSettings.XBPageQS, Convert.ToString(currentPage - 1), Convert.ToString(currentPage - 1)));
                }

                pagination.Append(String.Format("{0} ", Convert.ToString(currentPage)));

                if (currentPage + 1 <= maxPages)
                {
                    pagination.Append(String.Format("<a href=\"?{0}={1}\">{2}</a> ", XBSettings.XBPageQS, Convert.ToString(currentPage + 1), Convert.ToString(currentPage + 1)));
                }

                if (currentPage + 2 <= maxPages)
                {
                    pagination.Append(String.Format("<a href=\"?{0}={1}\">{2}</a> ", XBSettings.XBPageQS, Convert.ToString(currentPage + 2), Convert.ToString(currentPage + 2)));
                }

                if (currentPage + 1 <= maxPages)
                {
                    pagination.Append(String.Format("<a href=\"?{0}={1}\">{2}</a> ", XBSettings.XBPageQS, Convert.ToString(currentPage + 1), settingsItem.NextPageText));
                    pagination.Append(String.Format("<a href=\"?{0}={1}\">{2}</a> ", XBSettings.XBPageQS, Convert.ToString(maxPages), settingsItem.LastPageText));
                }
            }



            return(pagination.ToString());
        }
 public static double?ToDoubleN(this object obj)
 {
     if (obj == null)
     {
         return(null);
     }
     if (obj is bool)
     {
         return(Convert.ToDouble(obj));
     }
     return(double.TryParse(obj.ToString().Replace(".", ","), NumberStyles.Any, Culture, out double tmpvalue) ? tmpvalue : (double?)null);
 }
 private static void RegisterDecimalConversions(
     ITypeConverterRegistry registry)
 {
     registry.Register <decimal, short>(from => SysConv.ToInt16(from));
     registry.Register <decimal, int>(from => SysConv.ToInt32(from));
     registry.Register <decimal, long>(from => SysConv.ToInt64(from));
     registry.Register <decimal, ushort>(from => SysConv.ToUInt16(from));
     registry.Register <decimal, uint>(from => SysConv.ToUInt32(from));
     registry.Register <decimal, ulong>(from => SysConv.ToUInt64(from));
     registry.Register <decimal, float>(from => SysConv.ToSingle(from));
     registry.Register <decimal, double>(from => SysConv.ToDouble(from));
     registry.Register <decimal, string>(from =>
                                         from.ToString("E", CultureInfo.InvariantCulture));
 }
 private static void RegisterSingleConversions(
     ITypeConverterRegistry registry)
 {
     registry.Register <float, byte>(from => SysConv.ToByte(from));
     registry.Register <float, short>(from => SysConv.ToInt16(from));
     registry.Register <float, int>(from => SysConv.ToInt32(from));
     registry.Register <float, long>(from => SysConv.ToInt64(from));
     registry.Register <float, ushort>(from => SysConv.ToUInt16(from));
     registry.Register <float, uint>(from => SysConv.ToUInt32(from));
     registry.Register <float, ulong>(from => SysConv.ToUInt64(from));
     registry.Register <float, decimal>(from => SysConv.ToDecimal(from));
     registry.Register <float, double>(from => SysConv.ToDouble(from));
     registry.Register <float, string>(from =>
                                       from.ToString(CultureInfo.InvariantCulture));
 }
Example #11
0
 private static void RegisterInt64Conversions(
     DefaultTypeConverter registry)
 {
     registry.Register <long, byte>(from => SysConv.ToByte(from));
     registry.Register <long, short>(from => SysConv.ToInt16(from));
     registry.Register <long, int>(from => SysConv.ToInt32(from));
     registry.Register <long, ushort>(from => SysConv.ToUInt16(from));
     registry.Register <long, uint>(from => SysConv.ToUInt32(from));
     registry.Register <long, ulong>(from => SysConv.ToUInt64(from));
     registry.Register <long, decimal>(from => SysConv.ToDecimal(from));
     registry.Register <long, float>(from => SysConv.ToSingle(from));
     registry.Register <long, double>(from => SysConv.ToDouble(from));
     registry.Register <long, string>(from =>
                                      from.ToString(CultureInfo.InvariantCulture));
 }
Example #12
0
 /// <summary>
 /// 转换函数
 /// </summary>
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     try
     {
         double v1 = Converts.ToDouble(value);
         double v2 = Converts.ToDouble(parameter);
         if (v1 > v2)
         {
             return(Visibility.Visible);
         }
     }
     catch (Exception)
     {
     }
     return(Visibility.Collapsed);
 }
Example #13
0
 private static object ConvertValue(string keyValue, string locale)
 {
     if (keyValue.StartsWith("I'"))
     {
         return(Convert.ToInt64(keyValue.Substring(2)));
     }
     if (keyValue.StartsWith("F'"))
     {
         return(Convert.ToDouble(keyValue.Substring(2)));
     }
     if (keyValue.StartsWith("D'"))
     {
         return(Convert.ToDateTime(keyValue.Substring(2), (locale == null ? CultureInfo.CurrentCulture : new CultureInfo(locale))));
     }
     return(keyValue.Replace("\\n", "\n").Replace("\\t", "\t"));
 }
Example #14
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     try
     {
         var bytes      = Conv.ToDouble(value);
         var iterations = 0;
         while (bytes > 1024d && ++iterations < Sizes.Length)
         {
             bytes /= 1024d;
         }
         var size = Sizes.ElementAtOrDefault(iterations);
         return(string.Format("{0:F2} {1}", bytes, size));
     }
     catch (Exception)
     {
         return(null);
     }
 }
Example #15
0
        /// <summary>
        /// 由IPGW返回的字符串格式化
        /// </summary>
        internal FlowInfo GetIpgwDataInf(string data)
        {
            if (string.IsNullOrEmpty(data))
            {
                return(null);
            }
            FlowInfo info = new FlowInfo();

            try {
                string[] t = data.Split(new char[] { ',' });
                info.Data    = FluxFormater(t[0]);
                info.Balance = SysConvert.ToDouble(t[2]);
                info.Time    = DateTime.Now;
                //TODO::计算时间差
            }
            catch {
                return(null);
            }
            XmlDataProvider.Instance.AddNode(info);
            return(info);
        }
 public static double GetObjectValue(object value)
 {
     if (value == null || value == DependencyProperty.UnsetValue)
     {
         return(0d);
     }
     if (value is double)
     {
         return((double)value);
     }
     else if (value is string)
     {
         double d;
         double.TryParse((string)value, out d);
         return(d);
     }
     else
     {
         return(SysConvert.ToDouble(value));
     }
 }
Example #17
0
        public DataTable DeserializeDataTable(string name, List <System.Type> colTypes = null)
        {
            var theTable = new DataTable(name);

            /*----------------------------------
             * A first pass to read the header
             * and infer the data types
             * ---------------------------------*/
            var columnNames = new List <string>();
            var columnTypes = new List <Type>();
            int columnCount = 0;
            int counter     = 0;

            using (StringReader reader = new StringReader(_csv)) //Read line by line
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (line == "")
                    {
                        continue;
                    }

                    if (counter == 0)
                    {
                        var tokens = line.Split(',');
                        columnCount = tokens.Length - 1;
                        for (int i = 1; i <= columnCount; ++i)
                        {
                            columnNames.Add(tokens[i]);
                        }
                    }
                    else if (colTypes != null && counter == 1)
                    {
                        var tokens = line.Split(',');
                        columnCount = tokens.Length - 1;
                        for (int i = 1; i <= columnCount; ++i)
                        {
                            columnTypes.Add(this.GuessType(tokens[i]));
                        }
                    }
                    else
                    {
                        break;
                    }

                    counter++;
                }
            }

            if (colTypes != null)
            {
                columnTypes = colTypes;
            }
            for (int i = 0; i < columnCount; ++i)
            {
                theTable.Columns.Add(columnNames[i], columnTypes[i]);
            }

            /*----------------------------------
             * A second pass to read the data
             * ---------------------------------*/
            counter = 0;
            using (StringReader reader = new StringReader(_csv))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (line == "")
                    {
                        continue;
                    }

                    if (counter == 0)
                    {
                        counter++;
                        continue;
                    }

                    DataRow row = theTable.NewRow();

                    var tokens = line.Split(',');
                    for (int i = 0; i < columnCount; ++i)
                    {
                        if (columnTypes[i] == typeof(DateTime))
                        {
                            row[i] = Convert.ToDateTime(tokens[i + 1]); // +1 because first column is not used.
                        }
                        else if (columnTypes[i] == typeof(double))
                        {
                            row[i] = Convert.ToDouble(tokens[i + 1]);
                        }
                        else if (columnTypes[i] == typeof(int))
                        {
                            row[i] = Convert.ToInt32(tokens[i + 1]);
                        }
                        else
                        {
                            row[i] = tokens[i + 1];
                        }
                    }

                    theTable.Rows.Add(row);
                    counter++;
                }
            }
            return(theTable);
        }
Example #18
0
 public double ToDouble(object value)
     => SystemConvert.ToDouble(value);
Example #19
0
        protected static internal object ConvertValue(Type type, NSJSValue value)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            object o = FetchValue(type, value);

            if (type == typeof(int))
            {
                o = (o == null ? 0 : Converter.ToInt32(o));
            }
            else if (type == typeof(uint))
            {
                o = (o == null ? 0u : Converter.ToUInt32(o));
            }
            else if (type == typeof(short))
            {
                o = (o == null ? (short)0 : Converter.ToInt16(o));
            }
            else if (type == typeof(ushort))
            {
                o = (o == null ? (ushort)0 : Converter.ToUInt16(o));
            }
            else if (type == typeof(sbyte))
            {
                o = (o == null ? (sbyte)0 : Converter.ToSByte(o));
            }
            else if (type == typeof(byte))
            {
                o = (o == null ? (byte)0 : Converter.ToByte(o));
            }
            else if (type == typeof(long))
            {
                o = (o == null ? 0L : Converter.ToInt64(o));
            }
            else if (type == typeof(ulong))
            {
                o = (o == null ? 0ul : Converter.ToUInt64(o));
            }
            else if (type == typeof(float))
            {
                o = (o == null ? 0f : Converter.ToSingle(o));
            }
            else if (type == typeof(double))
            {
                o = (o == null ? 0d : Converter.ToDouble(o));
            }
            else if (type == typeof(decimal))
            {
                o = (o == null ? 0m : Converter.ToDecimal(o));
            }
            else if (type == typeof(char))
            {
                o = (o == null ? '\0' : Converter.ToChar(o));
            }
            else if (type == typeof(DateTime))
            {
                long ticks = 0;
                if (o is long)
                {
                    ticks = (long)o;
                }
                else if (o != null)
                {
                    ticks = Converter.ToInt64(o);
                }
                o = NSJSDateTime.LocalDateToDateTime(ticks);
            }
            else if (type == typeof(string))
            {
                if (o == null)
                {
                    o = null;
                }
                else if (!(o is string))
                {
                    o = o.ToString();
                }
            }
            else if (typeof(NSJSValue).IsAssignableFrom(type))
            {
                return(type.IsInstanceOfType(value) ? value : null);
            }
            return(o);
        }
Example #20
0
 double IConvertible.ToDouble(IFormatProvider? provider)
 {
     return Convert.ToDouble(m_value);
 }
Example #21
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 => (double)value * Converter.ToDouble(parameter);
 public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture) => SysConvert.ToDouble(value) * (SysConvert.ToDouble(parameter) / 100);
Example #23
0
        /// <summary>
        /// A calculator to calculate.
        /// </summary>
        private void Calculate()
        {
            Console.WriteLine("Pick the operator you like to use \n" +
                              "\n" +
                              "___________________________________________________________________________________________________________\n\n" +
                              "1. +\n" +
                              "2. -\n" +
                              "3. *\n" +
                              "4. /\n" +
                              "5. Return\n" +
                              "___________________________________________________________________________________________________________\n\n" +
                              "");
            var input = Console.ReadLine();

            switch (input)
            {
            case "1":
                _operator = "+";
                break;

            case "2":
                _operator = "-";
                break;

            case "3":
                _operator = "*";
                break;

            case "4":
                _operator = "/";
                break;

            case "5":
                Return();
                break;

            default:
                Console.WriteLine("This isn't a valid option");
                Return();
                break;
            }
            Console.Clear();
            Console.WriteLine("Pick the first number you want to use in your calculation\nCalculation: {0} {1} {2}", _number1, _operator, _number2);
            _number1 = Console.ReadLine();
            Console.Clear();
            Console.WriteLine("Pick the second number you want to use in your calculation\nCalculation: {0} {1} {2}", _number1, _operator, _number2);
            _number2 = Console.ReadLine();
            Console.Clear();
            if (_number1 == "")
            {
                _number1 = "1";
            }

            if (_number2 == "")
            {
                _number2 = "1";
            }

            Console.WriteLine("Calculation: {0} {1} {2}\nPress enter for your answer", _number1, _operator, _number2);
            Console.ReadLine();
            Console.Clear();
            switch (_operator)
            {
            case "+":
                _answer = Convert.ToDouble(_number1) + Convert.ToDouble(_number2);
                break;

            case "-":
                _answer = Convert.ToDouble(_number1) - Convert.ToDouble(_number2);
                break;

            case "*":
                _answer = Convert.ToDouble(_number1) * Convert.ToDouble(_number2);
                break;

            case "/":
                _answer = Convert.ToDouble(_number1) / Convert.ToDouble(_number2);
                break;
            }
            _number1 = "...";
            _number2 = "...";
            Console.WriteLine("The answer is: {0}\nPress enter to exit", _answer);
            Console.ReadLine();
            Main();
        }
Example #24
0
		double IConvertible.ToDouble (IFormatProvider provider)
		{	
			return Convert.ToDouble (Value, provider);
		}