在C#中,如何使用显着超过UInt64最大值(18,446,744,073,709,551,615)的数字进行存储和计算?
解决了一个错误,我得到了一些有趣的发现.
这个程序的结果
static void Main(string[] args)
{
int i4 = 4;
Console.WriteLine("int i4 = 4;");
Console.WriteLine("i4 % 1 = {0}", i4 % 1);
double d4 = 4.0;
Console.WriteLine("double d4 = 4.0;");
Console.WriteLine("d4 % 1 = {0}", d4 % 1);
Console.WriteLine("-----------------------------------------------------------");
int i64 = 64;
double dCubeRootOf64 = Math.Pow(i64, 1.0 / 3.0);
Console.WriteLine("int i64 = 64;");
Console.WriteLine("double dCubeRootOf64 = Math.Pow(i64, 1.0 / 3.0) = {0}", dCubeRootOf64);
Console.WriteLine("dCubeRootOf64 = {0}", dCubeRootOf64);
Console.WriteLine("dCubeRootOf64 % 1 = {0} ?????????????? Why 1. ??????????", dCubeRootOf64 % …Run Code Online (Sandbox Code Playgroud) 这个程序应该适用于这个条件,至少我认为,但是对于某些值,它并没有像预期的那样工作.
static void Main(string[] args)
{
double num, temp = 0;
double frac;
int j = 1;
num = 1034.264;
do
{
j = j * 10;
Console.WriteLine(j);
temp = num * j;
Console.WriteLine(temp);
}
while ((temp % 10)!=0);
}
Run Code Online (Sandbox Code Playgroud)
价值1034.347,其工作正常 -
但是对于价值1034.235 不能正常工作1034.235, 这将是无限的