David David - 1 year ago 123
C# Question

How to generate double numbers in c#

Thanks everyone i got the library of numbers, but i still have a problem.
This code bellow is only able to generate all numbers from 0.000000000000000000000000000001 to 0.999999999999999999999999999999
,but i need ALL NUMBERS from 0.009999999999999999999999999999 to 0.099999999999999999999999999999.
So i modified it and know its stuck on 0.01, so its printing in a file only 0.01 every time its in a loop, and it's not getting bigger!
BENDER BENDING please help!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace double_generator
{
class Program
{
static void Main()
{
try
{
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\xexex\Desktop\green.txt"))
{
double number = 0.009999999999999999999999999999;

do
{
number += 0.000000000000000000000000000001;
file.WriteLine(number.ToString("N30"));
} while (number <= 0.099999999999999999999999999999);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}


}

Answer Source

Warning: the file produced is 33 gigabytes! The file is so large it is actually impossible to open.

try
{
    using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\user_pc\Desktop\test.txt"))
    {
        double number = 0;
        do
        {
            number += 0.000000000000000000000000000001;
            file.WriteLine(number.ToString("N30"));
        } while (number <= 0.999999999999999999999999999999);
    }
}
catch (Exception ex)
{
    Console.WriteLine(ex.ToString());
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download