简体   繁体   English

C#-如何将浮点数/指数结果转换/显示为完整/整数

[英]C# - How To Convert/Display a Floating-Point/Exponential Result into a Full/Whole Number

I am using C# inside .Net Environment. 我在.Net环境中使用C#。 I have some really large integer values entered by user which are than divided by each other and the result is displayed. 我有一些用户输入的非常大的整数值,它们之间会相互除以并显示结果。 Now we know that 4/2 = 2 is simple but what if we divide 现在我们知道4/2 = 2很简单,但是如果我们除以

.0232321312321312312312312321032132139813912839013809123801283012983901283012380129382190381209382190382190382109382109382109312/ 1200000232323213213213213878978398494849023834902348239048239048239048239048239048239048239048239048239048239048239048239048239048239048239048239048239048234902384902384902384902348239048239048234 .0232321312321312312312312321032132139813912839013809123801283012983901283012380129382190381209382190382190382109382109382109312 / 12000002323232132132132132138789783984948490238349023482390482390482390390390390390482390390390390390382382390482390902390382

The answer is like 1.93601056119411E-197 答案就像1.93601056119411E-197

I want to display the answer as a full decimal/floating point value instead of relying on E symbol. 我想将答案显示为完整的十进制/浮点值,而不是依赖于E符号。

I wrote some code 我写了一些代码

using System.Numerics;

BigInteger x = BigInteger.Parse("0232321312321312312312312321032132139813912839013809123801283012983901283012380129382190381209382190382190382109382109382109312");
BigInteger y = BigInteger.Parse("1200000232323213213213213878978398494849023834902348239048239048239048239048239048239048239048239048239048239048239048239048239048239048239048239048239048234902384902384902384902348239048239048234
")
BigInteger answer = BigInteger.Divide(x, y)
return answer.ToString("D")

I think that is what you are looking for, if you want the fractional part of the answer you'll have to do it all with the Complex type. 我认为这就是您要寻找的,如果您想要答案的小数部分,则必须使用Complex类型完成所有操作。 Its not clear what you are doing from the question. 目前尚不清楚您在做什么。

EDIT: 编辑:

How about this 这个怎么样

using System.Numerics;

BigInteger x = BigInteger.Parse("0232321312321312312312312321032132139813912839013809123801283012983901283012380129382190381209382190382190382109382109382109312");
BigInteger y = BigInteger.Parse("1200000232323213213213213878978398494849023834902348239048239048239048239048239048239048239048239048239048239048239048239048239048239048239048239048239048234902384902384902384902348239048239048234
")
Complex answer = Complex.Divide((Complex)x, (Complex)y)
return answer.ToString("F50") //If 50 decimal places is enough.

我使用.ToString("N0") ,当我遇到相同的问题时,似乎可以完成工作。

I assume that you not only want to preceed your value with "0.00..." but also want to see the "missing" digits after 411 . 我假设您不仅要在值前面加上“ 0.00 ...”,而且还希望看到411之后的“缺失”数字。

If that is the case, then you cannot do this with floating point data types, since the floating point data types in .NET simply do not have the required precision. 如果真是这样,则您不能使用浮点数据类型来执行此操作,因为.NET中的浮点数据类型根本不具有所需的精度。 You will need to resort to external libraries, such as, for example, W3b.Sine (untested, just found it through a quick Google search), which allow for arbitrary-precision decimals. 您将需要使用外部库,例如W3b.Sine (未经测试,刚刚通过Google的快速搜索找到了它),该库允许使用任意精度的小数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM