Format() 공개 메소드

Format the specified number into a string.
public Format ( double d, int digits ) : String
d double The number to parse.
digits int The number of fractional digits.
리턴 String
예제 #1
0
파일: LoadedRow.cs 프로젝트: jongh0/MTree
 /// <summary>
 ///     Construct a loaded row from an array.
 /// </summary>
 /// <param name="format">The format to store the numbers in.</param>
 /// <param name="data">The data to use.</param>
 /// <param name="extra">The extra positions to allocate.</param>
 public LoadedRow(CSVFormat format, double[] data, int extra)
 {
     int count = data.Length;
     _data = new String[count + extra];
     for (int i = 0; i < count; i++)
     {
         _data[i] = format.Format(data[i], 5);
     }
 }
예제 #2
0
 /// <summary>
 /// Convert an array of doubles to a comma separated list.
 /// </summary>
 /// <param name="format">The way to format this list.</param>
 /// <param name="result">This string will have the values appended to it.</param>
 /// <param name="data">The array of doubles to use.</param>
 public static void ToList(CSVFormat format, StringBuilder result,
                           double[] data)
 {
     result.Length = 0;
     for (int i = 0; i < data.Length; i++)
     {
         if (i != 0)
         {
             result.Append(format.Separator);
         }
         result.Append(format.Format(data[i], 20));
     }
 }
예제 #3
0
 /// <summary>
 /// Convert an IMLData to a comma separated list.
 /// </summary>
 /// <param name="format">The way to format this list.</param>
 /// <param name="result">This string will have the values appended to it.</param>
 /// <param name="data">The array of doubles to use.</param>
 public static void ToList(CSVFormat format, StringBuilder result,
                           IMLData data)
 {
     result.Length = 0;
     for (int i = 0; i < data.Count; i++)
     {
         if (i != 0)
         {
             result.Append(format.Separator);
         }
         result.Append(format.Format(data[i], EncogFramework.DefaultPrecision));
     }
 }
예제 #4
0
 /// <summary>
 /// Convert an array of doubles to a comma separated list.
 /// </summary>
 /// <param name="format">The way to format this list.</param>
 /// <param name="precision">The precision.</param>
 /// <param name="result">This string will have the values appended to it.</param>
 /// <param name="data">The array of doubles to use.</param>
 public static void ToList(CSVFormat format, int precision, StringBuilder result,
                           double[] data)
 {
     result.Length = 0;
     for (int i = 0; i < data.Length; i++)
     {
         if (i != 0)
         {
             result.Append(format.Separator);
         }
         result.Append(format.Format(data[i], precision));
     }
 }
예제 #5
0
        /// <summary>
        /// Save the dataset to a CSV file.
        /// </summary>
        /// <param name="targetFile">The target file.</param>
        /// <param name="format">The format to use.</param>
        /// <param name="set">The data set.</param>
        public static void SaveCSV(FileInfo targetFile, CSVFormat format, IMLDataSet set)
        {
            try
            {
                var file = new StreamWriter(targetFile.ToString());

                foreach (IMLDataPair data in set)
                {
                    var line = new StringBuilder();

                    for (int i = 0; i < data.Input.Count; i++)
                    {
                        double d = data.Input[i];
                        BasicFile.AppendSeparator(line, format);
                        line.Append(format.Format(d, EncogFramework.DefaultPrecision));
                    }

                    for (int i = 0; i < data.Ideal.Count; i++)
                    {
                        double d = data.Ideal[i];
                        BasicFile.AppendSeparator(line, format);
                        line.Append(format.Format(d, EncogFramework.DefaultPrecision));
                    }

                    file.WriteLine(line);
                }

                file.Close();
            }
            catch (IOException ex)
            {
                throw new EncogError(ex);
            }
        }
예제 #6
0
        /// <summary>
        /// Load financial data.
        /// </summary>
        /// <param name="ticker">The ticker symbol.</param>
        /// <param name="output">The output file.</param>
        /// <param name="outputFormat">The output format.</param>
        /// <param name="from">Starting date.</param>
        /// <param name="to">Ending date.</param>
        public void LoadAllData(String ticker, String output, CSVFormat outputFormat, DateTime from,
            DateTime to)
        {
            try
            {
                Uri urlData = BuildURL(ticker, from, to);
                WebRequest httpData = WebRequest.Create(urlData);
                var responseData = (HttpWebResponse) httpData.GetResponse();

                if (responseData != null)
                {
                    Stream istreamData = responseData.GetResponseStream();
                    var csvData = new ReadCSV(istreamData, true, CSVFormat.English);

                    TextWriter tw = new StreamWriter(output);
                    tw.WriteLine("date,time,open price,high price,low price,close price,volume,adjusted price");

                    while (csvData.Next())
                    {
                        DateTime date = csvData.GetDate("date");
                        double adjustedClose = csvData.GetDouble("adj close");
                        double open = csvData.GetDouble("open");
                        double close = csvData.GetDouble("close");
                        double high = csvData.GetDouble("high");
                        double low = csvData.GetDouble("low");
                        var volume = (long) csvData.GetDouble("volume");

                        var line = new StringBuilder();
                        line.Append(NumericDateUtil.DateTime2Long(date));
                        line.Append(outputFormat.Separator);
                        line.Append(NumericDateUtil.Time2Int(date));
                        line.Append(outputFormat.Separator);
                        line.Append(outputFormat.Format(open, Precision));
                        line.Append(outputFormat.Separator);
                        line.Append(outputFormat.Format(high, Precision));
                        line.Append(outputFormat.Separator);
                        line.Append(outputFormat.Format(low, Precision));
                        line.Append(outputFormat.Separator);
                        line.Append(outputFormat.Format(close, Precision));
                        line.Append(outputFormat.Separator);
                        line.Append(volume);
                        line.Append(outputFormat.Separator);
                        line.Append(outputFormat.Format(adjustedClose, Precision));
                        tw.WriteLine(line.ToString());
                    }

                    tw.Close();
                }
            }
            catch (WebException ex)
            {
                throw new QuantError(ex);
            }
        }
예제 #7
0
파일: NumberList.cs 프로젝트: jongh0/MTree
 /// <summary>
 /// Convert an IMLData to a comma separated list.
 /// </summary>
 /// <param name="format">The way to format this list.</param>
 /// <param name="result">This string will have the values appended to it.</param>
 /// <param name="data">The array of doubles to use.</param>
 public static void ToList(CSVFormat format, StringBuilder result,
                           IMLData data)
 {
     result.Length = 0;
     for (int i = 0; i < data.Count; i++)
     {
         if (i != 0)
         {
             result.Append(format.Separator);
         }
         result.Append(format.Format(data[i], EncogFramework.DefaultPrecision));
     }
 }
예제 #8
0
 /// <summary>
 /// Construct a loaded row from an IMLData.
 /// </summary>
 /// <param name="format">The format to store the numbers in.</param>
 /// <param name="data">The data to use.</param>
 /// <param name="extra">The extra positions to allocate.</param>
 public LoadedRow(CSVFormat format, IMLData data, int extra)
 {
     int count = data.Count;
     _data = new String[count + extra];
     for(int i = 0; i < count; i++)
     {
         _data[i] = format.Format(data[i], 5);
     }
 }
예제 #9
0
파일: NumberList.cs 프로젝트: neismit/emds
 public static void ToList(CSVFormat format, int precision, StringBuilder result, double[] data)
 {
     int num;
     result.Length = 0;
     if ((((uint) precision) + ((uint) num)) <= uint.MaxValue)
     {
         goto Label_007B;
     }
     if (0 == 0)
     {
         goto Label_0064;
     }
     Label_0022:
     if ((((uint) num) & 0) != 0)
     {
         goto Label_0064;
     }
     Label_0036:
     result.Append(format.Format(data[num], precision));
     num++;
     Label_004B:
     if (num < data.Length)
     {
         goto Label_0064;
     }
     if (((uint) num) >= 0)
     {
         return;
     }
     goto Label_007B;
     Label_0055:
     result.Append(format.Separator);
     goto Label_0022;
     Label_0064:
     if (num != 0)
     {
         goto Label_0055;
     }
     goto Label_0036;
     Label_007B:
     num = 0;
     if (0 != 0)
     {
         goto Label_0055;
     }
     goto Label_004B;
 }
예제 #10
0
 public void LoadAllData(string ticker, string output, CSVFormat outputFormat, DateTime from, DateTime to)
 {
     try
     {
         HttpWebResponse response;
         ReadCSV dcsv;
         TextWriter writer;
         DateTime time;
         double num;
         double num2;
         double num3;
         double num4;
         double num5;
         long num6;
         StringBuilder builder;
         Uri requestUri = x38c212309d8d5dd3(ticker, from, to);
         goto Label_029A;
     Label_0010:
         builder.Append(outputFormat.Format(num, this.Precision));
         writer.WriteLine(builder.ToString());
     Label_0034:
         if (dcsv.Next())
         {
             goto Label_01E2;
         }
         writer.Close();
         return;
     Label_0049:
         builder.Append(outputFormat.Separator);
         builder.Append(outputFormat.Format(num3, this.Precision));
         builder.Append(outputFormat.Separator);
         builder.Append(num6);
         builder.Append(outputFormat.Separator);
         if ((((uint) num4) + ((uint) num2)) >= 0)
         {
             goto Label_0010;
         }
         return;
     Label_00B3:
         builder.Append(outputFormat.Format(num2, this.Precision));
         builder.Append(outputFormat.Separator);
         builder.Append(outputFormat.Format(num4, this.Precision));
         if ((((uint) num6) | 4) == 0)
         {
             goto Label_0034;
         }
         builder.Append(outputFormat.Separator);
     Label_0116:
         builder.Append(outputFormat.Format(num5, this.Precision));
         goto Label_0192;
     Label_012E:
         builder.Append(NumericDateUtil.DateTime2Long(time));
         builder.Append(outputFormat.Separator);
         builder.Append(NumericDateUtil.x93295384d7a86d9d(time));
         if ((((uint) num6) | 3) == 0)
         {
             goto Label_020C;
         }
         if (-2147483648 == 0)
         {
             goto Label_01FE;
         }
         builder.Append(outputFormat.Separator);
         goto Label_00B3;
     Label_0192:
         if (0 == 0)
         {
             goto Label_0049;
         }
         return;
     Label_019D:
         builder = new StringBuilder();
         if (((uint) num4) >= 0)
         {
             goto Label_012E;
         }
         goto Label_027A;
     Label_01BE:
         num5 = dcsv.GetDouble("low");
         num6 = (long) dcsv.GetDouble("volume");
         goto Label_0243;
     Label_01E2:
         time = dcsv.GetDate("date");
         num = dcsv.GetDouble("adj close");
     Label_01FE:
         num2 = dcsv.GetDouble("open");
     Label_020C:
         num3 = dcsv.GetDouble("close");
         num4 = dcsv.GetDouble("high");
         if ((((uint) num3) - ((uint) num4)) <= uint.MaxValue)
         {
             goto Label_01BE;
         }
     Label_0243:
         if ((((uint) num6) & 0) == 0)
         {
             goto Label_019D;
         }
     Label_0257:
         writer.WriteLine("date,time,open price,high price,low price,close price,volume,adjusted price");
         if (((uint) num) >= 0)
         {
             goto Label_0034;
         }
         goto Label_019D;
     Label_027A:
         if ((((uint) num5) & 0) != 0)
         {
             goto Label_0116;
         }
         goto Label_0257;
     Label_029A:
         response = (HttpWebResponse) WebRequest.Create(requestUri).GetResponse();
         Stream responseStream = response.GetResponseStream();
         if (((uint) num5) < 0)
         {
             goto Label_00B3;
         }
         dcsv = new ReadCSV(responseStream, true, CSVFormat.English);
         writer = new StreamWriter(output);
         goto Label_027A;
     }
     catch (WebException exception)
     {
         throw new QuantError(exception);
     }
 }
예제 #11
0
 public static void SaveCSV(FileInfo targetFile, CSVFormat format, IMLDataSet set)
 {
     try
     {
         StreamWriter writer = new StreamWriter(targetFile.ToString());
         using (IEnumerator<IMLDataPair> enumerator = set.GetEnumerator())
         {
             IMLDataPair pair;
             StringBuilder builder;
             int num;
             double num2;
             int num3;
             double num4;
             goto Label_002E;
         Label_0016:
             if ((((uint) num2) + ((uint) num2)) >= 0)
             {
             }
         Label_002E:
             if (enumerator.MoveNext())
             {
                 goto Label_00F5;
             }
             goto Label_012F;
         Label_003F:
             writer.WriteLine(builder);
             goto Label_0117;
         Label_004B:
             BasicFile.AppendSeparator(builder, format);
             builder.Append(format.Format(num4, 10));
             num3++;
         Label_0069:
             if (num3 >= pair.Ideal.Count)
             {
                 if (3 != 0)
                 {
                     goto Label_003F;
                 }
             }
             else
             {
                 num4 = pair.Ideal[num3];
                 goto Label_004B;
             }
         Label_0094:
             BasicFile.AppendSeparator(builder, format);
             builder.Append(format.Format(num2, 10));
             num++;
         Label_00B0:
             if (num < pair.Input.Count)
             {
                 goto Label_0107;
             }
             num3 = 0;
             goto Label_0069;
         Label_00CF:
             if (15 == 0)
             {
                 goto Label_0069;
             }
             if ((((uint) num3) | 0xff) != 0)
             {
                 goto Label_0094;
             }
         Label_00F5:
             pair = enumerator.Current;
             builder = new StringBuilder();
             num = 0;
             goto Label_00B0;
         Label_0107:
             num2 = pair.Input[num];
             goto Label_00CF;
         Label_0117:
             if (-2147483648 != 0)
             {
                 goto Label_0016;
             }
         }
     Label_012F:
         writer.Close();
     }
     catch (IOException exception)
     {
         throw new EncogError(exception);
     }
 }