'表格中的幂指数是针对于10进制数的,所以E列这表示方法是错的,因为它是二进制数
'如果一定要用指数来表示那需要移位,就是/2或*2,估计还没有这表示方法的
'浮点计算会有误差的,数的精度决定的,并不是计算方法
Option Explicit
Sub abc()
Dim a, i, j, t, n
a = [a1].CurrentRegion.Resize(, 5).Value
For i = 2 To UBound(a)
For j = 1 To Len(a(i, 1)) '整数
t = Val(Mid(a(i, 1), j, 1))
n = t * 2 ^ (Len(a(i, 1)) - j) + n
Next
For j = 1 To Len(a(i, 2)) '小数
t = Val(Mid(a(i, 2), j, 1))
n = t * 2 ^ -j + n
Next
a(i, 3) = CStr(n): n = 0
For j = 1 To Len(a(i, 1))
If Mid(a(i, 1), j, 1) <> "0" Then Exit For
Next
If j < Len(a(i, 1)) + 1 Then
a(i, 4) = Mid(a(i, 1), j) & "." & a(i, 2)
Else
a(i, 4) = "0." & a(i, 2)
End If
If left(a(i, 4), 1) <> "0" Then '整数部分>0
n = InStr(a(i, 4), ".")
a(i, 5) = Replace(a(i, 4), ".", vbNullString)
a(i, 5) = left(a(i, 5), 1) & "." & Mid(a(i, 5), 2) & "E" & n - 2
Else
For j = 3 To Len(a(i, 4))
If Mid(a(i, 4), j, 1) <> "0" Then
a(i, 5) = Mid(a(i, 4), j, 1) & "." & Mid(a(i, 4), j + 1) & "E" & 2 - j
Exit For
End If
Next
End If
Next
[a1].Resize(UBound(a), UBound(a, 2)) = a
End Sub