[英]How Can I add two very large numbers in excel?
我想在excel中存儲兩個非常大的數字,然后將它們相加。 我的數字是這樣的:
324930313630311035156280330632053510851055146511
當我在單元格中輸入這個數字時,它只顯示 15 位數字。 當然我知道我可以將格式單元格更改為 text ,但是當我將其更改為 text 時,它是不可計算的。
非常感謝
這是一個用戶定義的函數,它將添加以字符串格式輸入的非常大的正整數。 udf 返回字符串格式以保留所有數字:
Public Function superadd(s1 As String, s2 As String) As String
Dim L1 As Long, L2 As Long, L3 As Long, Carry As Long
Dim v1 As Long, v2 As Long, zum As Long
L1 = Len(s1)
L2 = Len(s2)
L3 = Application.Max(L1, L2)
If L1 > L2 Then
For i = 1 To L1 - L2
s2 = "0" & s2
Next i
Else
For i = 1 To L2 - L1
s1 = "0" & s1
Next i
End If
Carry = 0
For i = L3 To 1 Step -1
v1 = CLng(Mid(s1, i, 1))
v2 = CLng(Mid(s2, i, 1))
zum = v1 + v2 + Carry
If i = 1 Then
superadd = CStr(zum) & superadd
Exit For
Else
If zum > 9 Then
superadd = Right(CStr(zum), 1) & superadd
Carry = CLng(Left(CStr(zum), 1))
Else
superadd = CStr(zum) & superadd
Carry = 0
End If
End If
Next i
End Function
像這樣使用:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.