将最大整数值存储为double的问题
double asa = 12123435352352349879798724395792347897947323979743526;
如何以double数据类型存储此数字请帮帮我。
double asa =12123435352352349879798724395792347897947323979743526;
how to store this number in double datatype please help me.
你不能,在实践中。 double不具有存储大数字的精度。
您可以通过添加D后缀来编译它以使编译器将其视为double而不是整数:
You can't, in practice. A double doesn't have the precision to store a number that big.
You can get it to compile by adding a "D" suffix to make the compiler treat it as a double rather than an integer:
double asa =12123435352352349879798724395792347897947323979743526D;
Console.WriteLine( "12123435352352349879798724395792347897947323979743526");
Console.WriteLine(asa);
Console.WriteLine("{0:00000000000000000000000000000000000000000000000000000}", asa);
但它打印的内容可能不是你想要的:
But what it prints is probably not what you want:
12123435352352349879798724395792347897947323979743526
1.21234353523524E+52
12123435352352400000000000000000000000000000000000000
如何打印12123435352352349879798724395792347897947323979743526像这样......
你不能用双 - 或浮点数,十进制数,甚至长数字打印它 - 它作为一个整数超过64位! />
如果添加对System.Numerics的引用并使用BigInteger,则可以将其用作数字:
"how to print it 12123435352352349879798724395792347897947323979743526 like this..."
You can't print it from a double - or a float, or decimal, or even a long - it exceeds 64 bits as an integer!
You can use it as a number if you add a reference to System.Numerics and use BigInteger:
double asa = 12123435352352349879798724395792347897947323979743526D;
BigInteger bi = BigInteger.Parse("12123435352352349879798724395792347897947323979743526");
Console.WriteLine("12123435352352349879798724395792347897947323979743526");
Console.WriteLine(asa);
Console.WriteLine("{0:00000000000000000000000000000000000000000000000000000}", asa);
Console.WriteLine(bi);
12123435352352349879798724395792347897947323979743526
1.21234353523524E+52
12123435352352400000000000000000000000000000000000000
12123435352352349879798724395792347897947323979743526
但请注意 - 这不是一个快速的课程!
But be aware - this is not a "quick" class!