将最大整数值存储为double的问题 [英] problem to store Biggest integer value in double

查看:89
本文介绍了将最大整数值存储为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!


这篇关于将最大整数值存储为double的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆