2017-06-23 92 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值時,數據可能會丟失。「 –