2017-06-23 91 views
-1
我无法添加大量

在一起,就像增加非常大的数字在VB.NET

8767657654576576546675676567656765676576567676789876567898765456897654567876545678765456787656789876567898765678000000000022222222222222222 

8765487654876548765487654876547876545678765478765478654567876567876545678765456786 

你知道这是怎么可能得到一个正常大的纯文本answer is either too small or too large to convert to decimal

我的代码:

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click 
    Dim value1 As String = message.Text 
    Dim value2 As String = mykey.Text 
    Dim total = Convert.ToDecimal(value1) + Convert.ToDecimal(value2) 
    sum.Text = String.Format("{0:n0}", total) 
End Sub 
没有得到错误号
+4

是,使用'System.Numerics.BigInteger ' – Rob

+0

它是一个导入或我添加到昏暗total = System.Numerics.BigInteger(value1)+ System.Numerics.BigInteger(value2) – alan7811

+0

这是一个类,所以你要导入'System.Numerics',然后使用它通过'新的BigInteger' – Rob

回答

0

使用BigInteger(.NET 4.0。起)

此导入添加到您的代码:

Imports System.Numerics 

当数值大于Int64更大,你将需要使用byte array constructerBigInteger.Parse

"If you use the Parse method to round-trip the string representation of a BigInteger value that was output by the ToString method, you should use the BigInteger.ToString(String) method with the "R" format specifier to generate the string representation of the BigInteger value. Otherwise, the string representation of the BigInteger preserves only the 50 most significant digits of the original value, and data may be lost when you use the Parse method to restore the BigInteger value."

+0

Dosent似乎工作米奇,我进口你说什么,并添加此: Dim value1 As String = message.Text Dim value2 As String = mykey.Text Dim number As BigInteger = BigInteger.Pow(UInt64.MaxValue,3) sum.Text = String.Format(“{0:n0}”,数字) – alan7811

+0

即时使用VS express 2012 – alan7811

+0

“如果使用Parse方法来往返ToString输出的BigInteger值的字符串表示形式方法,您应该使用带有“R”格式说明符的BigInteger.ToString(String)方法生成BigInteger值的字符串表示形式,否则,BigInteger的字符串表示形式只保留原始值的50个最高有效位,并且当您使用Parse方法来恢复BigInteger值时,数据可能会丢失。“ –