我怎样才能在C#100多个十进制数字? [英] How can I get more than 100 decimal digits in C#?
问题描述
是否有可能获得超过100位小数在C#?
Is it possible to get more than 100 decimal digits in C#?
如果有什么是code中的必要部分?
If yes what is the necessary portion of code?
在Java中有什么呼叫的BigDecimal
,但它仍然不能达到超过55位。
In Java there something call BigDecimal
but it still can't reach more than 55 digits.
推荐答案
下载J#可再发行获得J#类库。 这篇文章暗示有关如何使用它来获取ZIP-能力的.NET项目,并解释了一些关于BigDecimal的,但是作为Ramhound解释,这篇文章也比较老了。
Using J# libraries:
Download the J# Redistributable to obtain the J# class libraries. This article hints about how to use it to get ZIP-ability in your .NET projects, and explains a bit about BigDecimal, but as Ramhound explained, the article is relatively old.
下载后, vsjlib
添加到项目中。我在.NET 4.0中它没有工作,但它没有工作在2.0的项目。它包含一个BigDecimal类,等等。不知道,但是,如果让你达100小数,但你可能会尝试一下。
After download, add the vsjlib
to your project. It didn't work for me on .NET 4.0, but it did work on 2.0 project. It contains a BigDecimal class, among others. Not sure, however, if that gives you up to 100 decimals, but you might give it a try.
您可以下载一个包装的 MPIR 库的。NET这里(下载版0.2)。然后,请执行以下操作:
You can download a wrapper for the MPIR library for .NET here (download version 0.2). Then, do the following:
- DLL 添加文件
\包装。*。您的项目,确保每个构建它们复制到您的调试或发布目录。
- 添加
\包装\ xmpir.cs
到项目 -
添加以下code到项目:
- Add the the files
\wrapper.*.dll
to your project, make sure that on each built they are copied to your Debug or Release directory. - Add
\wrapper\xmpir.cs
to your project Add the following code to your project:
// set the precision to 512 bits (adjust this to your needs)
mpir.mpf_set_default_prec(512);
ulong default_prc = mpir.mpf_get_default_prec();
// init vars (important!)
mpir.mpf_t val = mpir.mpf_init_set_d(.5);
mpir.mpf_t result = mpir.mpf_init_set_ui(0);
// calculate 0.5^200
mpir.mpf_pow_ui(result, val, 200);
double dresult = mpir.mpf_get_d(result);
// convert result to a string, in the form 1.2345 (dot not in output) and exp holding exponent
long exp;
string sresult = mpir.mpf_get_string(out exp, 10, 0, result);
// free vars (important!)
mpir.mpf_clear(val);
mpir.mpf_clear(result);
注意变量 sresult
仅将显著数字。你必须添加逻辑打印指数为好,或者一串零的。
Note that the variable sresult
will only hold the significant digits. You'll have to add the logic for printing the exponent as well, or a bunch of zeroes.
结果是<$c$c>6.2230152778611417071440640537801242405902521687211671331011166147896988340353834411839448231257136169569665895551224821247160434722900390625E-60$c$c>
一个文档PDF文件展示了如何使用它更详细
A documentation PDF file on the full MPIR library shows how to use it in more detail.
这篇关于我怎样才能在C#100多个十进制数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!