C#>>有关数字的东西被搞砸了

Lid*_*hen -1 c#

所以这就是发生的事情:我输入一个数字,结果是它只写出1个数字:324,就像变量c无缘无故地得到这个值一样.

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("enter a number with change");
        double num = double.Parse(Console.ReadLine());
        num = (int)num;
        int c = 0;
        Console.WriteLine(num);
        while (num != 0)
        {
            num /= 10;
            c++;
        }
        Console.WriteLine(c);
    }
}
Run Code Online (Sandbox Code Playgroud)

D S*_*ley 9

如果可以代表每个实数,该程序应无限循环double.说你输入1.然后循环将它除以10,离开0.1.由于0.1不等于0,循环将继续,导致0.01等.

double但是,只能支持约的最小值5E-324,所以如果你得到一个小的数字并试图将它除以10,你将得到零.

所以你的程序循环大约324次,并在它获得足够小的数字后退出.