Преобразование Double в String и наоборот - C#
Формулировка задачи:
Нужно вызвать 1000000 раз первый метод. Доходит до 150 итерации, и то, последние значение выводит плохо в научной форме с Е... Нули тоже не могут быть( Помогите пожалуйста. ИМХО, нужно функцию другую вместо ToString().
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static double startval = 0.77052314;
static int n = 1000000;
static string cutString;
static double newrand;
static string newrandStr;
static int x = 35365;
static int seed = 3089;
static uint[] MT = new uint[623];
static int index = 0;
static int N = 624;
static int M = 397;
static uint[] A = new uint[2] { 0, 0x9908b0df };
static void Main(string[] args)
{
double Rand;
Console.WriteLine("1 метод" + "\n");
DateTime begin = DateTime.Now;
for (int i = 0; i < n; i++)
{
Rand = method1();
Console.WriteLine((i + 1) + " " + Rand + "\n");
}
DateTime end = DateTime.Now;
Console.WriteLine("Час роботи методу:" + Math.Abs(end.Millisecond - begin.Millisecond) + "MS\n");
Console.ReadKey();
}
static double method1()
{
newrand = startval * startval;
newrandStr = newrand.ToString();
cutString = newrandStr.Substring(6, 8);
cutString = "0," + cutString;
startval = double.Parse(cutString);
return startval;
}
}
}Решение задачи: «Преобразование Double в String и наоборот»
textual
Листинг программы
String.Format("{0:0.##}", 123.4567);