vb 分数转换为小数,小数循环时显示0.(循环节)无限不循环时显示前100位.重谢帮帮 兄弟

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/16 11:29:55

vb 分数转换为小数,小数循环时显示0.(循环节)无限不循环时显示前100位.重谢帮帮 兄弟
vb 分数转换为小数,小数循环时显示0.(循环节)无限不循环时显示前100位.重谢
帮帮 兄弟

vb 分数转换为小数,小数循环时显示0.(循环节)无限不循环时显示前100位.重谢帮帮 兄弟
下面的代码无限不循环时显示前500位
Private Sub Form_Load()
MsgBox GetDot(1, 111)
End Sub
Function GetDot(ByVal m As Integer, ByVal n As Integer)
Dim s As String
Dim arr() As Integer
ReDim arr(0)
Dim num As Integer
s = m \ n & "."
m = m Mod n
arr(0) = m
Do
Do
m = m * 10
s1 = s1 & m \ n
Loop While m < n And m > 0
m = m Mod n
x = BinSearch(arr, m, 0, num)
If x < 0 Then
num = num + 1
ReDim Preserve arr(num)
arr(num) = m
Else
Exit Do
End If
Loop While m And Len(s1) < 300
GetDot = s & s1
End Function
Public Function BinSearch(ByRef a, ByVal Key, Optional ByVal Left, Optional ByVal Right)
'二分法查找
Dim low As Integer, high As Integer
Dim m As Integer

If IsMissing(Left) Then Left = LBound(a)
If IsMissing(Right) Then Right = UBound(a)
low = Left: high = Right

BinSearch = Left - 1
Do While (low Key Then
high = m - 1
Else
low = m + 1
End If
Loop

End Function